[英]AngularJS deep filter through array in ng-repeat
我的问题看起来与其他问题相似。 但这是不同的。 请看下面的代码。
我想按对象数组过滤数据。
这是片段
的HTML
<div
ng-repeat="(key, value) in ledgerData.ledgers track by $index"
ledger-pop
index="$index"
ftype="ftypeUpdate"
itemdata="value"
acntlist="fltAccntList"
class='drEntryForm_{{$index}} pr'
name='drEntryForm_{{$index}}'
update-ledger="updateEntry(entry)"
novalidate
>
</div>
JS
$scope.ledgerDataata = {
"ForwardedBalance": {
"amount": 0,
"type": "CREDIT"
},
"creditTotal": 4008,
"debitTotal": 4008,
"balance": {
"amount": 4008,
"type": "CREDIT"
},
"ledgers": [
{
"transactions": [
{
"particular": {
"name": "Sarfaraz",
"uniqueName": "temp"
},
"amount": 1001,
"type": "DEBIT"
}
],
"description": "testing",
"tag": "testing"
},
{
"transactions": [
{
"particular": {
"name": "frnd",
"uniqueName": "frndafafaf14453422453110l26ow"
},
"amount": 2001,
"type": "CREDIT"
},
{
"particular": {
"name": "Rahul",
"uniqueName": "cake"
},
"amount": 3001,
"type": "DEBIT"
}
],
"description": "testing",
"tag": "testing",
}
]
}
我正在尝试过滤
ng-repeat="(key, value) in ledgerData.ledgers track by $index | filter:{transactions[0]:{type: 'DEBIT'}}"
但是出现错误
提前致谢 :-)
您需要编写嵌套的ng-repeat来解决此问题。
ledgerData.ledgers中事务数组的内部ng-repeat
<div ng-repeat="(keyOne, ledger) in ledgerData.ledgers track by $index"> {{ledger.description}} <div ng-repeat="(keyTwo, transaction) in ledger.transactions | filter:{type:'DEBIT'}"> {{transaction.type}} </div> </div>
其实我找到了解决方案。
我几乎没有angularjs-filter
搜索,并为angularjs-filter
库。
这是一个非常好的插件,用于filter dirty works
以及如何使用它的链接。
我如何获得成功:
html
ng-repeat="(key, value) in ledgerData.ledgers | pick: debitOnly track by $index"
AngularJS
$scope.debitOnly = (ledger) ->
'DEBIT' == ledger.transactions[0].type
而已。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.