【发布时间】:2012-02-10 00:25:05
【问题描述】:
我认为我的做法是错误的。这就是我想要做的,而不是使用 RequireJS 或 LABjs:
var APP = {};
APP._timers = {};
APP._timelines = {};
$.when(
$.getScript('/app/models/Timer.js'),
$.getScript('/app/models/Section.js'),
$.getScript('/app/collections/Timers.js'),
$.getScript('/app/collections/Sections.js'),
$.getScript('/app/views/SectionView.js'),
$.getScript('/app/views/APPView.js'),
$.Deferred(function(deferred){
$(deferred.resolve);
})
).done(function () {
alert('done');
console.log(APP.APPView);
var foo = new APP.APPView;
APP._timelines.main = new APP.Timers('main');
APP._timelines.branched = new APP.Timers('branched');
}).fail(function(){
alert('failed');
});
它正在警告failed,没有任何内容写入控制台。
如果我打开这些文件中的任何一个,比如APPView.js 并在文件的顶部或底部发出警告,我就会看到它出现。这是该文件的示例:
APP.APPView = Backbone.View.extend({
el : $("#app-view"),
initialize : function () {
alert('App view initialized'); // Never gets called
this.sectionVew = new APP.SectionView();
}
});
alert('Inside APPView.js'); // gets called
【问题讨论】:
-
在您的
alert('fail');之后输入如下内容:console.log(arguments),您可能会发现它正在返回有关问题的详细信息? -
为什么要创建一个可以立即自行解决的 Deferred?
-
@JohnFlatness 当 DOMReady 事件发生或已经发生时立即解决。
-
@KevinB 啊,我明白了,我跳过了那里的
$()。
标签: jquery backbone.js jquery-deferred