My problem is really weird. I’m working in phonegap.
I got a function called “krijgSpellen”. I call that function when “device ready” like so:
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
readFile();
var options = { frequency: 3000 };
watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
krijgSpellen(); <--
}
but here is the weird part, when I do this:
function krijgSpellen(){
$.getJSON("gegevens.txt",function(result){
// Get all the games
$.each(result.games, function(){
$(".gamelijst").append("<li><a href='' id=" + this.id + " data-theme='a'>"+ this.game + "</a></li>");
});
$(".gamelijst, $.mobile.activePage").listview('refresh');
});
};
That works, but when I do this:
function krijgSpellen(){
$.each(jsonopgehaald.games, function(){
$(".gamelijst").append("<li><a href='' id=" + this.id + " data-theme='a'>" + this.name + "</a></li>");
});
$(".gamelijst, $.mobile.activePage").listview('refresh');
};
It doesn’t work, and I have the same code on an hyperlink and when I click the hyperlink it does work. And I really need the method where it doesn’t work to do it.
By the way
jsonopgehaald = {"games":[{"id":"2","name":"bartje","photo":"photo2.png","description":"kimpe","length":"is","totalDownloads":"0","totalFinished":"0","locations":[{"id":"3","name":"loc21","photo":"loc21.jpg","description":"loc21","FK_Game_id":"2","lat":"51.0000","long":"4.0000","status":"0"},{"id":"5","name":"loc22","photo":"loc22.jog","description":"locatie 22","FK_Game_id":"2","lat":"51.2330","long":"40.2222","status":"1"}]},{"id":"3","name":"aa","photo":"photo3.jPg","description":"aa","length":"aa","totalDownloads":"0","totalFinished":"3","locations":[{"id":"4","name":"loc4","photo":"loc4.jpg","description":"loc4","FK_Game_id":"3","lat":"51.2191","long":"4.4021","status":"0"}]}]}
Try this:
I tested it and it works. Added the
indexandvalueto function().valueis a reference to the array you are currently in.