datas structure is similar to
[{"id":1,"name":"test"},{"id":13,"name":"test2"}]
Accurate filtering by id,
The following writing method will filter out all the data containing 1 in the id (for example, the above two will be filtered out), can precise filtering be done?
datas|filter:{id : 1}
ringa_lee2017-05-15 17:08:08
var target = 1;
var fitFun = function(data,target){
var result = [];
angular.forEach(data,function(value,key){
if(value.id==target){result.push(data[key])};
})
return result;
};
var t = fitFun(data,target);
console.log(t);
我想大声告诉你2017-05-15 17:08:08
.filter('idon1',function(){
return function(arr){
var returnArr = [];
var index = '1';
angular.forEach(arr,function(data,i){
if(index.indexOf(data.id) != -1){
returnArr.push(data);
}
})
return returnArr;
}
})
给我你的怀抱2017-05-15 17:08:08
The official has its own filtering specified attributes, which are included in the official examples
https://docs.angularjs.org/ap...
滿天的星座2017-05-15 17:08:08
I agree with the above, just use the official ones. For example, the official filters cannot meet the requirements, such as | date: There is no filtering of dates into Chinese, so just use JS to write a .filter filter yourself