I would like to ask:
I have a array with predefined order.
var order=new Array();
order[0]="Tesco";
order[1]="Interspar";
order[2]="Penny Market";
etc..
And i need to write out items in predefined order.
I can write out item in order as is, but i cannot writeout in predefined order.
$.each(mapdata, function(index, value) {
//IF IS CHAIN IN ARRAY obchody, exit LOOP , ELSE ADD CHAIN TO LIST
if (jQuery.inArray(value.retezecnazev, obchody) === -1) {
obchody.push(value.retezecnazev);
countOfProducts++;
//CHANGE DATE FORMAT
var choppedDate = value.platido.split('-');
var newDate = choppedDate[2] + "." + choppedDate[1] + "." + choppedDate[0];
$("ul").append("<li data-icon=\"false\"><a data-ajax=\"false\" href=\"show_flyer.html?id=" +
value.id +
"&countOfPages=" +
value.strany +
"&nameOfChain=" +
value.retezecnazev +
" \"><img style=\"margin-top:10px;\" src=\" " + value.img + " \"/><h3 style=\"font-size:1.5em;\">" +
value.retezecnazev +
"</h3><div class=\"pageCount\" style=\"font-size:0.7em;\">" +
value.strany +
" Stran</div><div style=\"font-size:0.7em;\" class=\"pageCount\">Platnost do: " +
newDate +
" </div></a> </li>");
}
});
Is anybody who can help me and know how it solve?
Thanks very much for any advice.
Do you want to sort the array the very first time it’s written and then leave it as is, or do you want to allow the user to sort the array after it’s already on the page? If you don’t care about sorting the array after the page has loaded, then apply a sort immediately before you loop over mapData:
http://www.w3schools.com/jsref/jsref_sort.asp