如何筛选angularjs的数据? [英] How to filter the data in angularjs?
问题描述
我想根据姓
和标题
属性来过滤数据,但它没有过滤。
I am trying to filter the data according to firstname
and title
properties but it's not filtering.
<label>by Name
<input type="text" ng-model="searchText.data.firstname"></label> |
<label>by Title
<select name="title">
<option value="">All</option>
<option value="">Zone Manager</option>
<option value="">Logistic agent</option>
</select></label>
<hr/>
<div ng-repeat="accDetails in acct_list | filter:searchText">
{{accDetails.data.firstname}} |
{{accDetails.data.lastname}} |
{{accDetails.title}}
</div>
JSON数据是:
The JSON data is:
$scope.acct_list = {
"0": {
"data": {
"firstname": "maeli",
"lastname": "mad",
//...
},
"title": "Shop"
},
"1": {
"data": {
//...
},
"title": "hotel"
}
}
下面是我的 plnkr
推荐答案
这过滤不工作的原因是因为过滤
仅适用于数组和你的 acct_list
不是数组。
The reason that filtering doesn't work is because filter
only works on arrays, and your acct_list
is not an array.
您可以将数据变成一个数组:
You can either change your data to an array:
$scope.acct_list = [
{
"data": {
"firstname": "maeli",
"lastname": "mad",
//...
},
"title": "Shop"
},
{
...
}
]
,或安排到控制器和 NG-重复
在一个数组。
下面是另一个相关的<一个href=\"http://stackoverflow.com/questions/14788652/how-to-filter-key-value-with-ng-repeat-in-angularjs\">SO问题的关于这一主题。
Here's another relevant SO question on this topic.
另外,不要忘了 NG-模式=searchText.title
添加到您的&LT;选择&GT;
,并填写在&LT;期权方式&gt;
值相应
Also, don't forget to add ng-model="searchText.title"
to your <select>
and fill-in the <option>
values accordingly.
这篇关于如何筛选angularjs的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!