1
所以我從Backbone.js的延長某些對象:骨幹:如何綁定模型到視圖
var MyModel = Backbone.Model.extend({});
var modelInstance = new MyModel();
var MyModelView = Backbone.View.extend({});
而且我試圖找出如何我的模型綁定到其相應的視圖。如何處理Backbone中的數據綁定?
所以我從Backbone.js的延長某些對象:骨幹:如何綁定模型到視圖
var MyModel = Backbone.Model.extend({});
var modelInstance = new MyModel();
var MyModelView = Backbone.View.extend({});
而且我試圖找出如何我的模型綁定到其相應的視圖。如何處理Backbone中的數據綁定?
創建它時將模型實例傳遞到視圖中。
var modelView = new MyModelView({model: modelInstance})
從the docs:
When creating a new View, the options you pass — after being merged into any default
options already present on the view — are attached to the view as this.options
for future reference. There are several special options that, if passed, will be
attached directly to the view: model, collection, el, id, className, tagName and attributes.