根据View
的{{1}}:
如果通过,将附加几个特殊选项 直接访问视图:
model
,collection
,el
,id
,className
,tagName
和attributes
。
我理解el
,id
& className
用于包装render()
中的任何内容,但
<{1}}对象中特殊如何model
和collection
?它们是否被View方法使用?
谢谢。
答案 0 :(得分:2)
不,View方法不使用此选项。 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;
},
...
};