我见过几个问题有关添加条件到NG-重复的过滤器,并没有这些选项对我工作过在NG-重复条件筛选
我有以下的自定义过滤器
app.filter('customFilter', function() {
return function (collection, type, seq) {
return !collection ? [] : collection.filter(function (item) {
return (type === 'DL' && item.del_seq === seq) || (type === 'PU' && item.pu_seq === seq)
});
}
});
而且,这是在我的指导
<tr ng-repear-start="parent in parentCollection">
<td> Do stuff with parent collection items info </td>
</tr>
<tr ng-repeat-end="">
<td colspan="100">
<table>
<tr ng-repeat="child in childCollection | customFilter: parent.Type:parent.seq">
<td>Do stuff with child info</td>
</tr>
</table>
</td>
</tr>
这项工作完美,但我想知道,如果有一种方法可以做到这样使用一个简单的过滤器?
我试着做以下
<tr ng-repeat="child in childCollection | filter: (parent.Type === 'PU' ? child.pu_seq: child.dl_seq) === parent.seq">
但没有奏效。认为这可能没有习惯?
编辑:按照要求,该样品JSON和也,调整一个更好的想法的HTML
parentCollection = [{seq: 1, type:'PU'},{seq: 2, type:'PU'},{seq: 3, type:'PU'},{seq: 4, type:'DL'}];
childCollection = [{pu_seq: 1, dl_seq:4},{pu_seq: 2, dl_seq:4},{pu_seq: 3, dl_seq:4}]
其结果将是,家长[0]将与孩子明细行[0] ,父母[1]与孩子[1],父母[2]与孩子[2]和父母[3]将具有3个孩子作为细节,因为所有3个孩子都有dl_seq:4,父母[4]是dl和它的序列是4
在这里发表您的JSON – Sajeetharan
@Sajeetharan JSON添加 – CJLopez