0
在JS我有一个变量data
与下面的XML:使用jQuery遍历XML深层结构 - IE9
<data>
<delivery>
<checklist>Pre-Vehicle Check Bulk</checklist>
<delivery>800056799</delivery>
<shipment>105065995</shipment>
<driverName>John Doe</driverName>
<driverLanguage>NL</driverLanguage>
<country>Belgium</country>
<product>01248741</product>
<productDescription>Metam 200%-33</productDescription>
<location>P0204A</location>
</delivery>
<questions>
<question>
<id>Question-1</id>
<driver>true</driver>
<operator>true</operator>
<isAnswered>false</isAnswered>
<answer/>
<options>
<option>OK</option>
<option>NOK</option>
<option>NA</option>
</options>
</question>
<question>
<id>Question-2</id>
<driver>true</driver>
<operator>false</operator>
<isAnswered>false</isAnswered>
<answer/>
<options>
<option>OK</option>
<option>NOK</option>
</options>
</question>
</questions>
</data>
我创建基于此XML一个JS对象。结果应该是一个有问题的数组。每个问题都有其属性和一系列选项。所以基本上,你在XML中看到questions
标签
这里下的相同结构的JS代码来生成对象:
var questions = [];
$(data).find("question").each(function(){
var options = [];
$(this).find("option").each(function(){
options.push($(this).text());
});
questions.push({
id : $(this).find("id").text(),
driver : $(this).find("driver").text(),
operator : $(this).find("operator").text(),
isAnswered : $(this).find("isAnswered").text(),
answer : $(this).find("answer").text(),
title : $(this).find("title").text(),
text : $(this).find("text").text(),
text_driver : $(this).find("text_driver").text(),
options : options
});
});
现在的问题是,选择没有得到补充。从调试器中我可以看到,在第一个.each
<option>
标签被从当前节点this
中删除之后。所以它的值是:
<options>OKNOKNA</options>
如何使用JQuery实现循环遍历多个XML级别?
编辑:它似乎与IE9有关,我需要让它在这个特定的浏览器上工作。
似乎为我工作。 http://jsfiddle.net/4shLrL2q/结果有一个选项数组。 – 2014-11-04 14:23:19
@squint事实上,它在铬中工作,我应该增加我的开发需求来运行我最大的敌人:IE9 – Hazaart 2014-11-04 14:26:33
我猜这是因为它认为这些是HTML'option'元素在一个无效的位置。尝试使用['jQuery.parseXML()'](http://api.jquery.com/jQuery.parseXML/)在将它传递给'$'之前解析它。 http://jsfiddle.net/4shLrL2q/1/ – 2014-11-04 14:31:46