开发者

narrowing xml results with jquery

开发者 https://www.devze.com 2023-03-30 04:44 出处:网络
I am trying to figure out how to pull specific data from an xml file using jquery\'s $.get method.Here\'s my simple xml file:

I am trying to figure out how to pull specific data from an xml file using jquery's $.get method. Here's my simple xml file:

<data> 

<set1>
<image>images/thumbs/test-9-thumb.jpg</image> 
<image>images/thumbs/test-2-thumb.jpg</image>
<image>images/thumbs/test-3-thumb.jpg</image>
</set1>

<set2>
<image>images/thumbs/test-3-thumb.jpg</image>
<image>images/thumbs/test-9-thumb.jpg</image> 
<image>images/thumbs/test-2-thumb.jpg</image>
<image>images/thumbs/test-3-thumb.jpg</image>
<image>images/thumbs/test-2-thumb.jpg</image>
</s开发者_如何学编程et2>

</data>

Here's my how I'm pulling the data. In this case I'm using this for the jcarousel plugin, but it doesn't really matter.

     function carousel_callback(carousel){
$('#live-edge-large img').bind('click', function(){
       $.get('ajax/xml-content.php',
    function(xml) {     
    mycarousel_itemAddCallback(carousel,carousel.first,carousel.last,xml);
        },
        "xml"
        );  
 });
};

What I need to do is to bring in the images in either the set1 or set2 tags depending on which #live-edge-large img is initially clicked.(there will be 5-10 images within the #live-edge-large div) So, the idea would be to get the index number of the #live-edge-large img, add 1 to that, and assign it to a variable, and use that to target the proper tag, set1 or set2. But I can't figure out how I would do this. Here the callback function which will add the images to the page:

        function mycarousel_itemAddCallback(carousel,first,last,xml) {

    $('image',xml).each(function(i) {       
    carousel.add(first+i, mycarousel_getItemHTML($(this).text()))
    });


      function mycarousel_getItemHTML(url) {
    return'<img src="' + url + '" width="128" height="95" ref="' + reference  +'"/>';

};

So the each statement is what I need to work on. I tried a few things, like this: function mycarousel_itemAddCallback(carousel,first,last,xml) {

    $('set[indexnumber] image',xml).each(function(i) {      
    carousel.add(first+i, mycarousel_getItemHTML($(this).text()))
    });

Where indexnumber is a variable representing the index number of the image that was originally clicked.

Also tried something like this:

var x="set"+indexnumber+" image";
$('x',xml).carousel.add(first+i, mycarousel_getItemHTML($(this).text()));

No joy on any of these ideas.

How can I use the index number (or custom variable, id, whatever), of the clicked #live-edge-large img to target the appropriate set of data?

Thanks.

0

精彩评论

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