Fix #2458 - Options are not attached to views.

This commit is contained in:
Brad Dunbar
2013-04-08 13:58:15 -04:00
parent afb9dfc6d8
commit a22cbc7f36
2 changed files with 15 additions and 24 deletions

View File

@@ -985,7 +985,7 @@
// if an existing element is not provided...
var View = Backbone.View = function(options) {
this.cid = _.uniqueId('view');
this._configure(options || {});
options = this._configure(options || {});
this._ensureElement();
this.initialize.apply(this, arguments);
this.delegateEvents();
@@ -1089,7 +1089,7 @@
_configure: function(options) {
if (this.options) options = _.extend({}, _.result(this, 'options'), options);
_.extend(this, _.pick(options, viewOptions));
this.options = options;
return options;
},
// Ensure that the View has a DOM element to render into.

View File

@@ -14,13 +14,10 @@ $(document).ready(function() {
});
test("constructor", 6, function() {
test("constructor", 3, function() {
equal(view.el.id, 'test-view');
equal(view.el.className, 'test-view');
equal(view.el.other, void 0);
equal(view.options.id, 'test-view');
equal(view.options.className, 'test-view');
equal(view.options.other, 'non-special-option');
});
test("jQuery", 1, function() {
@@ -156,28 +153,22 @@ $(document).ready(function() {
strictEqual(new View().el.id, 'id');
});
test("with options function", 3, function() {
var View1 = Backbone.View.extend({
test("with options function", 2, function() {
var View = Backbone.View.extend({
options: function() {
return {
title: 'title1',
acceptText: 'confirm'
};
return {title: 'title'};
},
initialize: function(options) {
strictEqual(options.title, 'title');
strictEqual(options.fixed, true);
}
});
var View2 = View1.extend({
options: function() {
return _.extend(View1.prototype.options.call(this), {
title: 'title2',
fixed: true
});
}
});
strictEqual(new View2().options.title, 'title2');
strictEqual(new View2().options.acceptText, 'confirm');
strictEqual(new View2().options.fixed, true);
new View({fixed: true});
});
test("with attributes", 2, function() {