從JSON完成拉取數據,但在循環中嘗試從子元素(即:子項1,2等)中提取附加信息時出現問題。Mootools JSON(拉Childs,Childeren)
{
"title": "Main Title",
"items": [
{
"title": "Sub Title 1 "
},
{
"title": "Sub Title 2",
"items": [
{
"title": "Sub Item 1" //CAN'T GET MY HANDS ON THESE ITEMS!!!!!
},
{
"title": "Sub Item 2"
}
]
},
{
"title": "Sub Title 3",
"items": [
{
"title": "Sub Item 1"
},
{
"title": "Sub Item 2"
}
]
},
{
"title": "Sub Title 4 "
}
]
}
這裏是我的嘗試,試圖拉「子項」到已經建立的李中的另一個UL認證。
var addItemsLi = function(itemsLi){
itemsLi.each(function(itemLi){
var el = new Element('li'),
name = new Element('a', {'html': itemLi.title}).inject(el);
if (itemLi.items){
var ul = new Element('ul'),
li = new Element('li').inject(ul),
subItem = new Element('a', {'html': itemLi.items.title}).inject(li);
};
el.inject(gallery);
});
};
非常感謝尼爾,你讓我完全瘋狂! – Starboy