我在ng-repeat中过滤我的JSON文件时遇到了麻烦。
以下是我的代码中的JSON数据来自Firebase
{
"850": {
"buttonText": "Button TST",
"description": "",
"documentNumber": "850",
"language": "fi",
"special": false,
"newOrder": 99000500850
},
"851": {
"buttonText": "eng ButtonTXT",
"description": "I would like to get this",
"documentNumber": "851",
"language": "en",
"special": false,
"newOrder": 99000500851
},
"852": {
"buttonText": "MORE FInnish button text",
"description": "Oh my",
"documentNumber": "852",
"language": "fi",
"special": false,
"newOrder": 99000500015
}
}
JSON数据存储在$ ctrl.documentMatrixFirebase中。这是Angular.js HTML。除了过滤部分之外,它是做我想要的东西。
<google-docs-card
layout="column"
ng-repeat="docButton in $ctrl.documentMatrixFirebase |
orderObjectBy:'newOrder' track by docButton.newOrder "
document-data="docButton"
subject="$ctrl.subject"
id="docnum_{{docButton.documentNumber}}"></google-docs-card>
这是我试图用来过滤而没有运气的代码。
<google-docs-card
layout="column"
ng-repeat="docButton in $ctrl.documentMatrixFirebase |
filter:docButton.language:'en' |
orderObjectBy:'newOrder' track by docButton.newOrder "
document-data="docButton"
subject="$ctrl.subject"
id="docnum_{{docButton.documentNumber}}"></google-docs-card>
如果可能的话,我想避免为这么简单的工作添加自定义过滤器。
答案 0 :(得分:0)
看起来AngularJs到Array过滤器解决了这个问题: https://github.com/petebacondarwin/angular-toArrayFilter
我按照说明安装了数组过滤器,并在HTML中使用它。
<google-docs-card
layout="column"
ng-repeat="docButton in $ctrl.documentMatrixFirebase
| toArray:false | filter: {language: 'en'}
| orderObjectBy:'newOrder' track by docButton.newOrder"
document-data="docButton"
subject="$ctrl.subject"
id="docnum_{{docButton.documentNumber}}"></google-docs-card>