2013-01-11 94 views
0

我想創建一個簡單的數組像item_structure = {thumb, head, cont}這裏是我的代碼:簡單的JSON陣列

$('.items_options').find('#'+item_id+' .option .blog_item_structure li') 
        .each(function(event) { 
    var item_class = $(this).attr('class'); 
    item_structure[] = item_class; 
}); 

但似乎expresion item_structure[] = ...不工作。那麼你們中的任何人都知道什麼是rigt語法?

Thx爲您的時間。

+3

這有什麼好做JSON。你只需要學習數組如何在JavaScript中工作,這應該在每一個好的教程中介紹。例如:https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Predefined_Core_Objects#Array_Object或http://eloquentjavascript.net/chapter4.html。 –

+0

item_structure = {thumb,head,cont}不是JSON – cggaurav

+0

Thx它幫了很多:) –

回答

0

你大概的意思是push值:

item_structure.push(item_class); 

這增加了item_classitem_structure最後一個元素。

對於這項工作item_structure必須是一個數組,最容易取得如此這樣說:

item_structure = [];