If Statements with XML



My code was trucking along fine until I ran into a problem. My XML data might not always be in order of the train number, so I have to append the train number based on the time of the next departure. I'm not sure how to form my string of 'if' statements to not break the code.


This is what I have so far:



$(data).find('service time:eq(0)').each(function() {
var nextTrain = $(this).find('name').text();

if ($(this).find('name:contains(2)').each(function() {
$('#slot01 #rt01a').append($('<h1 class="bullet"><span class="tl123"><span class="bgw">-</span>2</span></h1>'));
}));

if ($(this).find('name:contains(3)').each(function() {
$('#slot01 #rt01a').append($('<h1 class="bullet"><span class="tl123"><span class="bgw">-</span>3</span></h1>'));
}));

if ($(this).find('name:contains(4)').each(function() {
$('#slot01 #rt01a').append($('<h1 class="bullet"><span class="tl456"><span class="bgw">-</span>4</span></h1>'));
}));

if ($(this).find('name:contains(5)').each(function() {
$('#slot01 #rt01a').append($('<h1 class="bullet"><span class="tl456"><span class="bgw">-</span>5</span></h1>'));
}));
});


I have never been good with 'if' statements so I'm sure it's horribly written. My end goal is to take the next set of trains and find out if the trains x where x = 2, 3, 4, 5 it appends the appropriate text.


No comments:

Post a Comment