I’m building up a function in jQuery that populate an array from an XML.
The XML comes out of another application, so I cannot change it.
The function is meant to preload image after the array is created.
Everything works well except that I am not able to distinguish child tags with same name under different parent tags.
Well, here is the jQuery code:
(function() {
{
setTimeout(function(){
var splashArray = new Array();
// Load the Splash XML file and assign each image within to an array
$.get('images.xml', function(xml) {
The problem is here:
$('album', xml).each(function (i) {
var path = $(this).attr("lgpath");
$('img', xml).each(function (i) {
splashArray.push("/fotografie-matrimonio/" + path + $(this).attr("src"));
see below for the problem!
});
});
work_with_splash();
});
function work_with_splash () {
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
// Get the size of an object
var size = Object.size(splashArray);
var i = 0;
for(i=0; i<size; i++) new Image().src = splashArray[i];
/*alert(result[X]);*/
} //closes the spalsh Call
}, 1000);
};
and here the XML structure:
<album id="1" lgpath="thePath 1/" ...>
<img src="name of photo 1" ....></img>
<img src="name of photo 2"....></img>
<img src="name of photo 3"....></img>
</album>
<album id="2" lgpath="thePath 2/" ...>
<img src="name of photo 1" ....></img>
<img src="name of photo 2"....></img>
<img src="name of photo 3"....></img>
</album>
The script works, but what it does is the it load for each album path all the img src (also the ones of the others album path.
What I want to do is: to process the img tags in groups by the parent tags.
I don’t know if I am clear!
Thanks !!!
I’ve solved!
Easy…
just change the code from:
to:
using the .parent() method.
Hope it will help somebody!
Cheers 🙂