angular.js - filter数字,是否可以精确过滤
某草草
某草草 2017-05-15 17:06:08
0
4
554

datas结构类似于

[{"id":1,"name":"test"},{"id":13,"name":"test2"}]

通过id精确筛选,
以下写法会把id中含有 1 的数据都筛选出来(如以上两条都会被筛选出来),可以做精确筛选吗

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