angularJS過濾器使用

filter:從數組中選出一個子集,並將其作爲一個新數組返回。

使用:

HTML:{{filter_expression | filter:expression:comparator}}

JS:$filter(“filter”)(array,expression,comparator);

array:被過濾的數組。

expression:字符串/對象/函數,用於從數組中選擇數據的判斷表達式。使用$可以匹配任何字段。

comparator:函數/Boolean/undefined,用於確定預期的值(從filter表達式返回)和實際的值(數組中的對象)進行比較,應視爲匹配。function(actual,expected);

舉例:

var list = [];
list = [{codeName:'自費',codeId:'00'},{codeName:'醫保',codeId:'H1'}]
//獲取數組某些數據
var newList0 = $filter('filter')(list,{codeName:'自費'});

//獲取選中行數據
var isSelected = $filter('filter')(list, { isSelected: true });

var newList = list.filter(function (item) {
    return item.codeId=== 'H1';
});

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章