使用角度滤镜过滤数组

时间:2015-12-02 13:00:43

标签: angularjs

我有一个对象数组,我希望使用角度$filter

按传感器标签进行过滤
SensorPort: [0: {Port: "1"SensorLabel: "Temperature"},1: {Port: "2"SensorLabel: ""},2: {Port: "3"SensorLabel: ""}]

1 个答案:

答案 0 :(得分:1)

不确定,你想要实现什么。考虑一下你的数据:

 var sensorPortData = [{Port: "1", SensorLabel: "Temperature"},
         {Port: "2", SensorLabel: "Attempt"},
         {Port: "3", SensorLabel: "Nothing"}];

然后这样做,会给你:

 var searchQuery = "Tem";
 $filter('filter')(myData, {$: searchQuery}) == [{Port: "1", SensorLabel: "Temperature"},
        {Port: "2", SensorLabel: "Attempt"}]