0

我有这个数组:

[{
  "title": "Pirates of the Caribbean 5",
  "others": "lorem",
  "tags": "action,experimental,comedy"
},
{
  "title": "Toy Story 3",
  "others": "lorem",
  "tags": "animation,family,comedy"
},
{
  "title": "Pirates of the Caribbean 1",
  "others": "lorem",
  "tags": "action,adventure,comedy"
}]

我正在尝试获取标签为action的所有详细信息(标题,其他) 。

要查找字符串是否包含操作,我这样做:

$.getJSON('jsonpath.json', function(data) {
            var items = [];

            $.each(data, function(count,item) {
                var a = $.inArray("action", item.tags.split(","));

                if (a != -1){
                    console.log("Found")
                }

            });


        });

在这里之后我该怎么做才能附加/解析标题和其他带有动作标签的电影?

4

2 回答 2

0

找到后将项目推送到项目数组。

 var items = [];
 $.getJSON('jsonpath.json', function(data) {
        $.each(data, function(count,item) {
            var a = $.inArray("action", item.tags.split(","));

            if (a != -1){
                console.log("Found");
                items.push(item);
            } 
        });
    });
于 2013-07-05T10:19:42.433 回答
0

不确定我是否理解您的意图。

item.title您可以使用(在 each() 循环内)访问标题,其他使用item.others

于 2013-07-05T10:15:55.027 回答