我已经在SO中看到了类似的问题 Rendering a view after multiple asynchronous ajax calls with Backbone
不幸的是,解决方案对我来说表现得很奇怪 我可以看到在ajax完成之前调用了渲染
这是我的代码
var LoginView = Backbone.View.extend({
initialize : function(){
var _this = thisl
var templateLoading = $.get('template.html', function(template){
this.template = template;
});
$.when(templateLoading).done(function(){ _this.render()});
},
render : function(){
console.log('Rendering');
$.tmpl(this.template).appendTo(this.el);
}
});
AppRouter:
//Route
var view = new LoginView;
console.log('View in APP Router');
console.log(view.$el.html());
当我运行它时,它按此顺序打印
View in App Router
empty string
Rendering
我错过了什么?