Ric*_*lja 6 angularjs angularjs-ng-repeat angularjs-filter
所以我有一个存储在控制器变量中的公司数据集.
$scope.companies = [
{
name: "first company",
type: ["a", "b"]
},
{
name: "second company",
type: ["b"]
},
{
name: "third company",
type: ["c"]
}
]
Run Code Online (Sandbox Code Playgroud)
然后我有我的列表,我想列出a或b的所有公司.我认为发送和数组将作为一个或语句.原来它更像是一个声明.
<ul>
<li ng-repeat="company in companies | filter:filters{type: ['a', 'b']}">
{{company.name}}
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
上面的代码将列出"第一家公司",而我希望它列出"第一家公司"和"第二家公司".我知道我可以在控制器中操作$ scope.companies数据集,但我想知道是否有任何"原生"方法来实现这一点.
最好的祝福!//理查德
bas*_*rat 12
您唯一的选择是使用函数使用过滤器:
<ul>
<li ng-repeat="company in companies | filter:customFunction">
{{company.name}}
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
哪里
$scope.customFunction = function(item){ /* true if you want item, false if not */ }
Run Code Online (Sandbox Code Playgroud)
来源:http://docs.angularjs.org/api/ng.filter:filter #parameters
| 归档时间: |
|
| 查看次数: |
12467 次 |
| 最近记录: |