如何將這個JSON對象放在下面的函數或對象中?如何將動態生成的JSON對象集成到其他對象中?
// this function generates an JSON Object dynamically
$(".n_ListTitle").each(function(i, v) {
var node = $(this);
var nodeParent = node.parent();
var nodeText = node.text();
var nodePrice = node.siblings('.n_ListPrice');
var prodPrice = $(nodePrice).text();
var prodId = nodeParent.attr('id').replace('ric', '');
var prodTitle = nodeText;
var json = {
id : prodId,
price : prodPrice,
currency : "CHF",
mame : prodTitle
};
return json;
});
TDConf.Config = {
products : [
// here should be inserted the JSON Object
{id: "[product-id1]", price:"[price1]", currency:"[currency1]", name:"[product-name1]"},
{id: "[product-id2]", price:"[price2]", currency:"[currency2]", name:"[product-name2]"},
...
})],
containerTagId :"..."
};
如果不理解請諮詢:) 提前感謝幫助我弄清楚!如果你想將它添加到那麼你會做
TDConf.Config = {
products : []
};
$(".n_ListTitle").each(function(i, v) {
var node = $(this);
var nodeParent = node.parent();
var nodeText = node.text();
var nodePrice = node.siblings('.n_ListPrice');
var prodPrice = $(nodePrice).text();
var prodId = nodeParent.attr('id').replace('ric', '');
var prodTitle = nodeText;
var json = {
id : prodId,
price : prodPrice,
currency : "CHF",
name : prodTitle
};
TDConf.Config.products.push(json);
});
請解釋一下這個問題。你想插入作爲項目作爲產品數組中的n_listTitle元素? –