我应该如何将此 XML 对象放入 javascript 字典中?
来自 get_objectives.php 的 XML:
<container>
<objective>
<id>1</id>
<type>thing</type>
<name>banana</name>
<date_added>2012-05-08 21:13:01</date_added>
<released>2012-05-08 22:47:27</released>
</objective>
<objective>
<id>2</id>
<type>thing</type>
<name>hammock</name>
<date_added>2012-05-08 21:13:01</date_added>
<released>2012-05-08 22:47:27</released>
</objective>
</container>
我正在尝试修复的 javascript 不起作用:
function updateObjectives(){
$.post('scripts/get_objectives.php', {}, function(xml){
$(xml).find("objective").each(function(i){
objectives[i] = {}
objectives[i]['id'] = $('id', xml).text()
console.log("objectives["+i+"].id = "+objectives[i].id)
})
})
}
$('id', xml).text()
根据下面的控制台输出,我正在尝试的调用似乎没有卡在处理 find("objective").each 调用的函数中:
objectives[0].id = 12
objectives[1].id = 12