2013-07-05 17 views
0

我有此數組:的Javascript:獲取其中數組中的特定值包含文字(標籤)的陣列

[{ 
    "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" 
}] 

我試圖讓所有的細節(標題,其他),其中標籤是動作

要查找一個字符串是否包含動作我這樣做:

$.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") 
       } 

      }); 


     }); 

我該怎麼辦這裏後追加/解析電影的標題的和其它的標記作用?

回答

0

不知道我理解你的意圖。

您可以一次發現與item.title訪問標題和其他人(各()循環內部)與item.others

+0

我想追加所有帶標籤動作的標題。這就是全部 – jQuerybeast

+0

對不起,這基本上是一個錯誤的問題。感覺有點累。請標記爲關閉。 – jQuerybeast

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); 
      } 
     }); 
    }); 
相關問題