这是一个神奇的代码:
function() {
var result='';
for (var key in TRAINER_STEPS){
if (TRAINER_STEPS.hasOwnProperty(key)) {
$.get('steps/trainer.step.'+key+'.html')
.done(function(data) {
console.log(data); // HERE DATA IS VALID HTML DATA
result += '<div '+(key == TRAINER_DEFAULT_STEP ? 'class="hiddenStep"' : 'class="currentStep"')+' data-step="'+key+'">'+data+'</div>\n'; // AND HERE NOTHING HAPPEND
})
.fail(function(jqxhr, settings, exception) {
console.log("[el5s] Load step steps/trainer.step."+key+".html failed. Error: "+exception);
});
}
}
console.log(result); // EMPTY HERE
return result;
}
$.get 效果很好,并且数据被正确接收,但我的函数返回完全空的结果。看我的评论。它出什么问题了?