angular.js - filter numbers, whether it can be filtered accurately
某草草
某草草 2017-05-15 17:06:08
0
4
630

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}
某草草
某草草

reply all(4)
左手右手慢动作
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); 
我想大声告诉你
.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;
        }
    })
给我你的怀抱

The official has its own filtering specified attributes, which are included in the official examples
https://docs.angularjs.org/ap...

滿天的星座

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template