0
var homeView = Backbone.View.extend({
el: $("#main_container"),
initialize: function(){
_.bindAll(this, 'render');
},
render:function(){
$.get('/home', {}, function(data){
console.log(data);
var tpl = _.template(home_container_temp, {});
this.el.html(tpl);
});
}
});
我想做一个ajax GET请求,然后设置数据。但我不能这样做,因为我得到:如何在我的骨干视图中使用“this”?
Uncaught TypeError: Cannot call method 'html' of undefined
谢谢。为什么美元在var $ el前面签字?为什么不让美元退出? – TIMEX
@TIMEX'$ el'只是我的首选项,表明变量包含一个jQuery对象。它没有功能性后果。不管你想要什么,你都可以命名变量。 – kubetz