jquery - Multiple arrays in javascript doens't work passing values -
i'm trying create multidimensional arrays in js this:
on app.js file have
var equipvalue = new array(); var selectedtrucks = new array();
in function.js file instead have:
for (var in selectedtrucks) { (function(i){ // simple ajax request return me json values var ajaxurl = '/ajaxrequest/getsingletruckposition/' + selectedtrucks[i]; $.ajax({ url: ajaxurl, }) .done(function(data) { if(data != null){ // equipvalue doens't go. // unable set property '0' of undefined or null reference equipvalue[i] = jquery.parsejson(data); } });
why obtain: unable set property '0' of undefined or null reference ? why variables doens't work on function.js file selectedtrucks work perfectly?
thanks guy
edit
doing test i've tried this:
equipvalue = jquery.parsejson(data);
so, problem isn't scoope create multidimensional array on runtime? or similar?
** edit 2**
here problem:
var selectedtrucks = new array(); // other 15 lines of codes , this: if(selectedtrucks === undefined || selectedtrucks.length == 0){ cleanmapmarkers(); }
why cleanmapmakers() launched when selectedtrucks empty?? problems i've found here. thanks
- update : seems equipvalue changed, or overwritten different type, somewhere else.
in code, maybe you're looking for, if selectedtrucks undefined or if it's not empty
if(selectedtrucks === undefined || selectedtrucks.length != 0){ cleanmapmarkers(); }
- jquery.parsejson() parses json text object, callback returns object
.done(function(data) { if (data != null) { equipvalue[i] = data;
Comments
Post a Comment