Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

getValue for View::className and View::id

  • Loading branch information...
commit 51387ebc363bb8a7e2974941e97083a8bad5bdc3 1 parent 215805e
@gsamokovarov gsamokovarov authored
Showing with 15 additions and 2 deletions.
  1. +2 −2 backbone.js
  2. +13 −0 test/view.js
View
4 backbone.js
@@ -1290,8 +1290,8 @@
_ensureElement: function() {
if (!this.el) {
var attrs = _.extend({}, getValue(this, 'attributes'));
- if (this.id) attrs.id = this.id;
- if (this.className) attrs['class'] = this.className;
+ if (this.id) attrs.id = getValue(this, 'id');
+ if (this.className) attrs['class'] = getValue(this, 'className');
this.setElement(this.make(getValue(this, 'tagName'), attrs), false);
} else {
this.setElement(this.el, false);
View
13 test/view.js
@@ -135,6 +135,19 @@ $(document).ready(function() {
ok(!view.el);
});
+ test("View: with className and id functions", 2, function() {
+ var viewClass = Backbone.View.extend({
+ className: function() {
+ return 'one';
+ },
+ id: function() {
+ return 'two';
+ }
+ });
+ equal((new viewClass).el.className, 'one');
+ equal((new viewClass).el.id, 'two');
+ });
+
test("View: with attributes", 2, function() {
var view = new Backbone.View({attributes : {'class': 'one', id: 'two'}});
equal(view.el.className, 'one');
Please sign in to comment.
Something went wrong with that request. Please try again.