尝试过滤数组以获取角度的子集时出错

时间:2015-05-11 08:08:34

标签: angularjs

我正在尝试根据数组中某个参数的值过滤对象数组。但是,当我尝试做同样的事情时,会抛出错误"参数' [value]不是函数,未定义。

$ scope.model.selection将包含基于用户选择的数组值(比如复选框)

$scope.model.selection = ["m1", "m2"]

我编写了代码,只从json中获取_source值作为对象。现在我只想要通过特定条件的对象,即[" m1"]

中的机器名

我的代码:

var filter;
        filter = sourcearray.filter(function (filterinstance)
                                                  {
                  return filterinstance.machinename in $scope.model.selection;

                                                  });

我的数据:

{

        "kal": [
            {
                "_index": "log2015.18",
                "_type": "MT_DETAIL",
                "_sc": null,
                "_source": {
                    "value1": 0,
                    "value2": "2",
                    "value3": "MON",
                    "machine": "m1"
                },
                "sort": [
                    1
                ]
            },
            {
                "_index": "logw-2015.18",
                "_type": "MT_DETAIL",
                "_sc": null,
                "_source": {
                    "value1": 1,
                    "value2": "3",
                    "value3": "MON1",
                    "machine": "m1"
                },
                "sort": [
                    2
                ]
            },
            {
                "_index": "log-2015.18",
                "_type": "MT_DETAIL",
                "_sc": null,
                "_source": {
                   "value1": 3,
                    "value2": "265",
                    "value3": "MON2",
                    "machine": "m2"
                },
                "sort": [
                    3
                ]
            },
            {
                "_index": "log2015.18",
                "_type": "MT_DETAIL",
                "_sc": null,
                "_source": {
                   "value1": 4,
                    "value2": "5",
                    "value3": "MON5",
                    "machine": "m2"
                },
                "sort": [
                    1
                ]
            },
            {
                "_index": "log2015.18",
                "_type": "MT_DETAIL",
                "_sc": null,
                "_source": {
                    "value1": 7,
                    "value2": "3",
                    "value3": "MON8"
                },
                "sort": [
                    1
                ]
            }
        ]

}

0 个答案:

没有答案