コレクションへのビュー バインドを定義しました。
1) ビューを初期化すると、コレクションのフェッチ呼び出しが実行されます。
2) get リクエストの結果を見ると
問題ありません。 3) render 関数を呼び出すために (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
}
});