开发者

jQuery XML Traversing

I have the following XML format and would like to get the list of markers for each category using jQuery.

<categories>
    <category id="1">
        <marker />
        <marker />
        <marker />
    </category>
    <category id="2">
        <marker />
        <marker />
        <marker />
    </category>
    <category id="3">
        <marker />
        <marker />
        <marker />
    </category>
</categories>

I am loading the XML correctly using jQuery with an AJAX call and when I use jQuery.find().each I am getting anywhere. Am I doing it wrong?

$(data).find('category[id=1] > mar开发者_如何学Pythonker').each(function() {}
$(data).find('categories category[id=1] > marker').each(function() {}


Your first solution would be correct, except that you're missing the closing );.

Example: http://jsfiddle.net/vyFeZ/

$(data).find('category[id=1] > marker').each(function() {
    // do something
});


A sample from my code , replace the names with your code

// process your code inside the loops

 $(callback).find('CartClass Shipments Shipment Items Item').each(function() {                       
                        $(callback).find('EstimatedArrivalDate Item').each(function() {

});

                    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜