我在下面有一个JavaScript代码。

bgCustom = { 'items':[], 'items_num':3, 'element':'#bg_custom_thumbs', 'next': '#bg_custom_next_thumb', 'prev': '#bg_custom_prev_thumb', 'width':165 };
//populate array
bgCustom.items = [["images/backgrounds/bear-ears_thumb.jpg", "bear-ears.jpg", "Bear-Hair"], ["images/backgrounds/blue-swirls_thumb.jpg", "blue-swirls.jpg", "WaterSmoke"]];


我如何动态创建bgCustom.items数组。表示我想要一个数组列表

[['val1_1','val1_2','val1_3'],['val2_1','val2_2','val2_3']]


有谁能够帮助我。

最佳答案

bgCustom = { 'items':[], 'items_num':3, 'element':'#bg_custom_thumbs', 'next': '#bg_custom_next_thumb', 'prev': '#bg_custom_prev_thumb', 'width':165 };

function PushToItems(a,b,c) {
    var ar = [a,b,c];
    bgCustom.items.push(ar);
}

PushToItems("images/backgrounds/bear-ears_thumb.jpg", "bear-ears.jpg", "Bear-Hair");


这应该使它更具动态性。

09-30 13:36