したがって、2つのモデルをバックボーンビューに渡します。ビューの初期化関数内からthis.options.model2を使用して2番目のモデルを取得します。
App.MyView = Backbone.View.extend({
initialize: function() {
this.stateModel = this.options.model2;
// test to make sure the stateModel is being set correctly. This works.
console.log("test: : " + this.stateModel.get("blah"));
// Save scroll position in model2 on scroll
$( window ).on( 'scroll', function () {
this.stateModel.set("savedScrollY", this.pageYOffset);
});
});
スクロールすると、次のエラーが発生します。
TypeError:式の結果'this.stateModel'[undefined]はオブジェクトではありません。
これは、トリガーがオフになったときにアプリがどのスコープにあるかを理解していない結果だと思います。