0

根据backbone.jsView doc :

有几个特殊选项,如果通过,将直接附加到视图 :modelcollectionelidclassName和。tagNameattributes

我了解el, id&className用于包装任何内容render(),但是

一个物体有多 特别?_ View 方法是否使用它们?modelcollectionView

谢谢你。

4

1 回答 1

2

不,查看方法不使用此选项。model并且collection只会成为 View 对象的属性。引用来源:

// List of view options to be merged as properties.
var viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName'];

// Set up all inheritable **Backbone.View** properties and methods.
_.extend(View.prototype, Events, {

  ...
  // Performs the initial configuration of a View with a set of options.
  // Keys with special meaning *(model, collection, id, className)*, are
  // attached directly to the view.
  _configure: function(options) {
    if (this.options) options = _.extend({}, this.options, options);
    for (var i = 0, l = viewOptions.length; i < l; i++) {
      var attr = viewOptions[i];
      if (options[attr]) this[attr] = options[attr];
    }
    this.options = options;
  },
  ...

};

于 2012-05-30T23:10:32.043 回答