2016-07-28 65 views
0

我想在角控制器來過濾兩個表達式和兩個比較器功能我用循環代碼一個以上的表達和比較器工作正常

angular.forEach(vm.campaignData, function (value) { 
       if (value.startTime < today && value.endTime > today) { 
        vm.campaignFilteredData.push(value); 
       } 
      }); 

,但我想用$過濾器,但它不工作

vm.campaignFilteredData =$filter('filter')(vm.campaignData, {startTime : today , endTime: today} , 
      function(actual, expected) { return actual < expected;},function(actual, expected) { return actual > expected;}); 

我的數據是這樣的

[{

"name": "Levis Marketing Event Vadodra Himalaya Mall", 
"tenantId": 1, 
"locationId": 5, 
"createdByName": "sg_area_manager", 
"startTime": 1462300200000, 
"endTime": 1462473000000, 
"description": "This event for Marketing Levis Vadodra Himalaya Mall", 
"metricIds": [], 
"comparisionStartTs": 0, 
"comparisionEndTs": 0 

},{

"name": "Levis Festival Event Vadodra Himalaya Mall", 
"tenantId": 1, 
"locationId": 5, 
"createdByName": "sg_area_manager", 
"startTime": 1462300200000, 
"endTime": 1462473000000, 
"description": "This event for Festival Levis Vadodra Himalaya Mall", 
"metricIds": [], 
"comparisionStartTs": 0, 
"comparisionEndTs": 0 

}]

+1

你能重現與的jsfiddle或Plunker一些數據? –

+0

您好@RomeshJain我的其他過濾器工作完美,像這樣==> vm.campaignFilteredData = $ filter('filter')(vm.campaignData,{startTime:today},function(actual,expected){return actual> expected;}) ; –

+0

好的!但是,如果您提供數據並且哪些不起作用,這將會很有幫助。另外提一下,預計會有什麼結果。 –

回答

1

不是一個理想的解決方案,但它能夠完成任務。儘管更好地創建自己的角度過濾器。

https://jsfiddle.net/ygL8rnb8/

vm.campaignFilteredData = $filter('filter')(vm.campaignData, 
     function(value) { 
     if (value.startTime < today && value.endTime > today) { 
      return true; 
     } 
     } 
    );