Angularjs不计算0的假值

时间:2016-02-17 13:08:57

标签: javascript angularjs

嘿伙计们我有拖曳json数组的对象。它们包含这样的属性 对象1:

    $scope.list01 = [
           {
               "key":"00.00","value":"1"
           },{
               "key":"00.15","value":"1.3"
           },{
               "key":"00.30","value":"1.8"
           },{
               "key":"00.45","value":"1.9"
           },{
               "key":"01.00","value":"4"
           },{
               "key":"01.15","value":"3"
           },{
               "key":"01.30","value":"7.5"
           },{
               "key":"01.45","value":"0"
           },{
               "key":"02.00","value":"22.3"
           }];

和另一个json对象

   $scope.list02 = [
           {
               "key":"00.00","value":"1"
           },{
               "key":"00.15","value":"1.3"
           },{
               "key":"00.30","value":"1.8"
           },{
               "key":"00.45","value":"1.9"
           },{
               "key":"01.00","value":"0"
           },{
               "key":"01.15","value":"13"
           },{
               "key":"01.30","value":"13"
           },{
               "key":"01.45","value":"13"
           },{
               "key":"02.00","value":"28"
           }
       ];

我想比较两个对象并在新数组中显示不同的值我使用像这样的角度过滤器

        .filter("different",function(){
           return function(input,compares){
               var newArray = [];

               for(i=0;i<input.length;i++){
                   var foundMatch = false;
                   for(j=0;j<compares.length;j++){
                       if(compares[j].value == input[i].value ){
                          foundMatch = true;
                           newArray.push({
                               value:input[i].value,
                               key:input[i].key

                           })
                           compares[j]++;
                           break;
                       }
                   }
                   if(!foundMatch){
                       newArray.push({
                           value:input[i].value,
                           key:input[i].key

                       })
                   }
               }

               return newArray;
           }
       });

并像我这样在我的DOM上使用过滤器

{{compare | differentvalue:filterer}}

问题是输出不包含零值。 过滤器没有获得0值,我将0更改为“0”,过滤器正常工作。关于如何解决这个问题的任何想法?

1 个答案:

答案 0 :(得分:0)

从第一个数组返回值的建议(如果不同)。

&#13;
&#13;
content
&#13;
&#13;
&#13;