我試圖在數據加載後返回一個回調值,林可能看着這一切都是錯誤的。不知道如何返回回調函數 - 需要替代解決方案
var loadFromDatabase = function(callback){
if (!obj.data.myarray) {
// the problem is here, the jquery obj returns the ajax request obj
return $.getJSON('http://validjson',function(data){
obj.data.myarray = data.myarray;
return callback();
});
} else {
return callback();
}
};
var findObjInArray = function(){
// need i to be returned, but isnt working in the if statement, but works in the else statement
return loadFromDatabase(function(){
var l = obj.data.myarray.length;
for (var i = 0; i < 50;i++) {
if (i === 30) {
return i;
}
}
});
};
var myval = findObjInArray();
console.log(myval);
謝謝,這個作品完美。 – Sveisvei 2009-11-03 14:00:00