所以我尝试从 xml 文件中提取数据,如下所示:
<example>
<phrase>phrase1</phrase>
<word>
<definition>definition1</definition>
</word>
<word>
<definition>definition2</definition>
</word>
</example>
我希望能够将定义1和定义2作为数组的单独成员,现在我将它们像这样合并:definition1definition2
这是我的代码:
var $example = $xml.find("example");
$example.each(function(){
list.push($(this).children("word").children("definition").text());
});
有人有想法吗? 谢谢
最佳答案
如果要使用JQuery,则需要更改
$example.each(function(){
list.push($(this).children("word").children("definition").text());
});
至
$example.children("word").children("definition").each(
function() {
list.push($(this).text());
});
关于javascript - 从 xml 文件中获取子项的子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38476361/