子阵列上的角度 ng-repeat 过滤器 [英] Angular ng-repeat filter on subarray
问题描述
使用 Angular,我尝试在 FactorName 上使用 ng-repeat 过滤给定以下架构.
过滤使用<... ng-model="query.Factors.FactorName" ...> 不起作用(不足为奇).我还没有看到任何人试图以这种方式进行过滤的文献.
Angular 是否支持基于子数组元素属性的过滤?
<预><代码>[{"姓名":"1",因素":[{"FactorName":"FactorOne",类型":某种类型"},{"因子名称":"因子二",类型":某种类型"}]},{"姓名":"2",因素":[{"因子名称":"因子三",类型":某种类型"},{"因子名称":"因子四",类型":某种类型"}]}]还有另一个地方可以迭代数组,与 ng-repeat 一起工作,在带有自定义过滤器的双重绑定中.
HTML
<li>{{ x.Factors |因子过滤器 }}
JS
app.filter('factorFilter', function() {返回函数(项目){var 结果 = [];如果(项目){for (var i = 0; i < items.length; i++) {结果 = items[i]['FactorName'];}返回结果;} 别的 {返回 'Doh!';}}})
Using Angular, I'm trying to filter using ng-repeat on FactorName given the following schema.
Filtering using
<... ng-model="query.Factors.FactorName" ...> doesn't work (not surprisingly).
I haven't seen literature on anyone trying to filter in this way.
Does Angular support filtering based on a subarray element property ?
[
{
"Name":"1",
"Factors":[
{
"FactorName":"FactorOne",
"Type":"SomeType"
},
{
"FactorName":"FactorTwo",
"Type":"SomeType"
}
]
},
{
"Name":"2",
"Factors":[
{
"FactorName":"FactorThree",
"Type":"SomeType"
},
{
"FactorName":"FactorFour",
"Type":"SomeType"
}
]
}
]
There is also another place where you can iterate on a array, working along side ng-repeat, in the double bindings with a custom filter.
HTML
<ul ng-repeat="x in factorData">
<li>
{{ x.Factors | factorFilter }}
</li>
</ul>
JS
app.filter('factorFilter', function() {
return function(items) {
var results = [];
if (items) {
for (var i = 0; i < items.length; i++) {
results = items[i]['FactorName'];
}
return results;
} else {
return 'Doh!';
}
}
})
这篇关于子阵列上的角度 ng-repeat 过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!