来自多个字段的角度Typeahead筛选器
Angular Typeahead filter from more than one field
我有一个基于人名进行筛选的typeahead。我的person对象有更多的字段,而不仅仅是name(至少是{name, surname}
),并且我希望过滤器基于name和姓氏来工作。
这是当前的预编型,基于angular-ui-bootstrap
:
<input type="text" id="friendInput" placeholder="Friend's name"
typeahead="friend for friend in friendsList | filter:{name:$viewValue}"
typeahead-template-url="friendDropdown.html" ng-model="chosenFriend" />
我尝试过编辑typeahead
属性的filter
部分,但我想我没有找到正确的方法。正确的方法是什么?
您可以在您的作用域中声明一个过滤器并使用它
<input type="text" id="friendInput" placeholder="Friend's name"
typeahead="friend for friend in friendsList | filter:nameFilter"
typeahead-template-url="friendDropdown.html" ng-model="chosenFriend" />
在你的控制器中声明
$scope.nameFilter = function(friend) {
var regex = new RegExp('' + $scope.chosenFriend, 'i');
return regex.test(friend.name) || regex.test(friend.surname); // test on both field
}
相关文章:
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- 使用AngularJS中的筛选器更新给定的表
- 淘汰搜索/筛选
- AngularJS单选筛选不适用于Name、Description和Field4复选框值
- Angular JS Filter-通过3个复选框进行筛选
- Twitter引导程序Typeahead-Id&标签
- 对具有ui typeahead的对象中的值执行orderBy
- 当查询不在displayField中时,引导Ajax Typeahead不显示结果
- 如何让typeahead在我的搜索栏中填充自定义参数
- 使用下拉列表筛选列表(ul>li)
- 一旦加载并渲染了角度引导typeahead,就使用回调
- JQuery DataTable列筛选器-选择下拉筛选器
- Regex,用于从字符串中筛选关键字
- 使用多个条件筛选ng个重复
- 在筛选网格期间,网格负载掩码不起作用
- 更改 Twitter Typeahead 返回的内容
- 接下来选择与筛选器匹配的选项
- 可以't从AJAX请求中筛选数据
- Model中的Typeahead返回空值以形成输入字段
- 来自多个字段的角度Typeahead筛选器