![](/img/trans.png)
[英]Dynamically get the sum of columns with ng-option filter in AngularJS
[英]ng-option filter not working angularjs
我正在嘗試使用ng-options在select中顯示來自數組的數據,但我想過濾它不起作用。 我不想顯示具有billHeadShortForm = FEC&FDG的對象
這是我的HTML
<select class="form-control" ng-init="getBillHeadCurrentProjWise()" ng-model="headID" ng-options="h.billHeadID as h.billHead for h in billHeadsProjWise | filter:h.billHeadShortForm!='FEC' | h.billHeadShortForm!='FDG'">
<option value="">--Select Billing Head--</option>
</select>
我找到了解決方案
$scope.myFunction = function (Billhead) {
if (Billhead.billHeadShortForm == 'FEC' || Billhead.billHeadShortForm == 'FDG' || Billhead.billHeadShortForm == 'GL') {
return false;
} else {
return true;
}
}
ng-options="h.billHeadID as h.billHead for h in billHeadsProjWise | filter:myFunction"
將ng-options
的過濾器部分調整為以下內容:
ng-options="... | filter: {billHeadShortForm: '!FEC'} | filter: {billHeadShortForm: '!FDG'}"
見小提琴
雖然,您可能希望閱讀過濾器文檔 ,並編寫函數來避免用管道輸送兩個過濾器。
編輯:
該功能可能是這樣的:
$scope.filterBillHead = function (billHead) {
// Exclude 'FEC' and 'FDG'
// return true if billHeadShortForm is not in the array, false otherwise
return ['FEC', 'FDG'].indexOf(billHead.billHeadShortForm) < 0;
}
模板:
ng-options="... | filter: filterBillHead"
查看更新的小提琴
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.