javascript - Angular ui-bootstrap typeahead 选择多个

标签 javascript angularjs typeahead

搜索一个人时是否可以显示与该人相关的所有内容。并且还必须选择多个人。

这是我的示例代码......

<!doctype html>
<html ng-app="plunker">
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.js"></script>
    <script src="http://angular-ui.github.com/bootstrap/ui-bootstrap-tpls-0.2.0.js"></script>
    <script src="example.js"></script>
    <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
  </head>
  <body>

<div class='container-fluid' ng-controller="TypeaheadCtrl">
    <input type="text" ng-model="selectedStuff" typeahead="stuff as stuff.desc for stuff in stuffs | filter:{name: $viewValue, desc: $viewValue}"/>
    <span>{{selectedStuff.name}}</span>
    <span>{{selectedStuff.desc}}</span>
</div>
  </body>
</html>

和js代码......

angular.module('plunker', ['ui.bootstrap']);
function TypeaheadCtrl($scope) {

  $scope.stuffs= [
                {
                 "name":"thing1",
                 "desc":"this is the first thing",
                 "title": "this is the first title"
                },
                {
                 "name":"thing2",
                 "desc":"this is the second thing",
                 "title": "this is the second title"
                }
               ]
}

当我搜索时,它仅显示名称或描述或标题,但我需要显示全部三个属性而不是一个属性。

我需要选择多个类似的标签..

请帮忙解决这个问题。

提前致谢

最佳答案

我认为你需要将你的 html 更改为

<input type="text" ng-model="selectedStuff" 
typeahead="stuff as stuff.name + ' ' +stuff.desc + ' ' + stuff.title for stuff in stuffs | filter:{name: $viewValue, desc: $viewValue}"/>

关于javascript - Angular ui-bootstrap typeahead 选择多个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29789542/

相关文章:

javascript - Twitter 提前输入,Bloodhound 过滤器开始

javascript - 无法从使用 Express.js 和 SQL Server 创建的 api 获得任何响应

mysql - 如何使用Angular JS检索数据并在MYSQL列中存储json格式

jquery - Twitter Bootstrap 3 Typeahead/Tagsinput 完成两次

javascript - 为什么 jasmine spy 不通过引用解析函数对象?

javascript - 在 Spring Boot 应用程序中从 Angular JS 调用 Rest 服务时出错

css - 元素的大小在不应该调整的时候调整

javascript - contentEditable 在特定元素内设置插入符号

javascript - 如何发送和接收大型 JSON 数据

javascript - 插入不匹配列名的对象