[英]How to define custom filter for ui-select module in AngularJS?
Here is the code from select-field in html: 这是html中select字段中的代码:
<ui-select ng-model="group.selected" theme="selectize" ng-click="searchDisabled(3)" ng-disabled="disabledGroup">
<ui-select-match placeholder="Choose a group">
{{$select.selected.name}}
</ui-select-match>
<ui-select-choices repeat="group in groups | filter: $select.search">
<span ng-bind-html="group.name | highlight: $select.search"></span>
<small ng-bind-html="group.code | highlight: $select.search"></small>
</ui-select-choices>
</ui-select>
Then the field who's important to filter the table list: 然后是对表列表进行过滤很重要的字段:
<tr ng-repeat="item in filteredNames = (nameslist | filter:search | selectGroup:group.selected)">
<td>{{ item.lname }}</td>
<td>{{ item.fname }}</td>
<td>{{ item.maxAge }}</td>
</tr>
I'm using the ngModel value from ui-select-tag in the custom filter selectGroup as parameter for the filter. 我正在使用自定义过滤器selectGroup中ui-select-tag的ngModel值作为过滤器的参数。
The nameslist values are coming from the database. 名称列表值来自数据库。 Here the JSON result of a GET Request by QR_Group DB-Table: 这是QR_Group DB-Table的GET请求的JSON结果:
{
"QR_Name":[
{ "Id":31, "lname":"Bricks", "fname":"Johnny", "maxAge":24, "QR_GroupId":6 },
{ "Id":4, "lname":"Schon", "fname":"Toni", "maxAge":54, "QR_GroupId":6 },
{ "Id":56, "lname":"Houston", "fname":"Monica", "maxAge":29, "QR_GroupId":6 },
],
"Id":6,
"name":"South America",
"code":"SA"
}
This JSON format I'm getting from the WebAPI method GetGroup. 我从WebAPI方法GetGroup获得这种JSON格式。 How can I display the QR_Name array on the table list with the custom filter? 如何使用自定义过滤器在表列表上显示QR_Name数组?
This was my first thought: 这是我的第一个想法:
testApp.filter('selectGroup', ['$log', function ($log) {
return function (nameslist, group) {
group = group || '';
$log.info('fondslist:', fondslist);
$log.info('Filter for group:', group);
var selectList = [];
angular.forEach(fondslist, function (input) {
if (group == input.QR_Name['QR_GroupId']) {
selectList.push(input);
}
});
}
}]);
But the filter doesn't work correctly. 但是过滤器无法正常工作。
angular ui-select在0.12中使用group-filter属性添加了对自定义过滤器的支持-https: //github.com/angular-ui/ui-select/pull/836
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.