我已經定義了綁定到集合的視圖。取回集合時未調用渲染函數
1)當我初始化視圖時,執行集合上的獲取調用。 2)如果我看看獲取請求的結果,這是好的
3)我想觸發此變化(在myCollection中)調用渲染功能,但它不起作用。
這裏是我的代碼部分:
define([
"MyCollection",
"!text/template"
], function (myCollection, myTemplate) {
var myView = Backbone.View.extend({
initialize: function()
{
myCollection.bind('change', this.render); // why the render is not called when
// I perform the fetch even if the data is correctly loaded?
myCollection.fetch(); // it works
},
render: function()
{
// some code
this.$el <-- undefined
}
});
return myView;
});
如果我使用
1)
initialize: function()
{
myCollection.bind('reset', this.render); // this.$el <-- undefined in render call, Why?
myCollection.fetch(); // it works
}
2)
myCollection.fetch({
success: function() {
that.render(); // <-- here the $el is defined and it works, Why myCollection.bind('reset', this.render); not??
// it seems to me that when I use reset the render function is called before the this.$el is defined
}
});
成功完成change事件如果我在復位改變我得到以下信息:'遺漏的類型錯誤:無法調用未定義的方法'html'。在我的問題中更多詳細信息 – underscore666