Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery对XML节点进行排序,然后加入它们_Javascript_Jquery_Sorting - Fatal编程技术网

Javascript 使用jQuery对XML节点进行排序,然后加入它们

Javascript 使用jQuery对XML节点进行排序,然后加入它们,javascript,jquery,sorting,Javascript,Jquery,Sorting,下面是模式的基本知识。。。不止这些,但这让我很好地了解了我需要完成的任务: <item> <name>This is some product name to sort with dictionary sort.</name> <price value="29.99">$29.99</price> </item> <item> <name>This is some produc

下面是模式的基本知识。。。不止这些,但这让我很好地了解了我需要完成的任务:

<item>
    <name>This is some product name to sort with dictionary sort.</name>
    <price value="29.99">$29.99</price>
</item>
<item>
    <name>This is some product name to sort with dictionary sort.</name>
    <price value="29.99">$29.99</price>
</item>

添加到ItemsOrted数组时,可以使用…parent().get(0);将节点而不是jQuery对象添加到数组中

然后在最后一次迭代之后:

jQuery("item", xml).remove();
jQuery.each(itemsSorted, function() {
    jQuery(xml).append(this);
});

另外,您应该知道,您还没有在for循环中定义变量“i”。这使得它成为一个全局变量,并可能导致许多奇怪的行为。我更喜欢使用jQuery.each,因为它还提供了for循环中的局部范围:)

Awesome。关键是我试图动态创建一个新元素并将jQuery对象附加到其中,或者使用数组并找出如何将元素连接在一起。我需要做的是修改原始XML对象文档。谢谢
jQuery( "item", xml ).each(function() {
    alert( jQuery( "price", this ).text() );
});
jQuery("item", xml).remove();
jQuery.each(itemsSorted, function() {
    jQuery(xml).append(this);
});