From db43d0028bd53278ce0dc152f35db89cfc22d24f Mon Sep 17 00:00:00 2001 From: Lior Chen Date: Sun, 14 Sep 2014 14:23:35 +0300 Subject: [PATCH 1/2] adds item attributes for collection items - fixes #1 --- README.md | 5 +++++ src/collection.js | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f10449ad..9710ee39 100644 --- a/README.md +++ b/README.md @@ -621,6 +621,10 @@ A template name or template function to use when rendering each model. If using A view class to be initialized for each item. Can be used in conjunction with `itemTemplate`. +### itemAttributes *view.itemAttributes* + +Attributes that will be passed to the constructor of each item. Can be used in conjunction with `itemView`. + ### itemContext *view.itemContext(model, index)* A function in the declaring view to specify the context for an `itemTemplate`, receives model and index as arguments. `itemContext` will not be used if an `itemView` is specified as the `itemView`'s own `context` method will instead be used. @@ -1049,6 +1053,7 @@ When rendering `this.collection` many properties will be forwarded from the view - `itemView` - `itemContext` - `itemFilter` +- `itemAttributes` - `emptyTemplate` - `emptyView` - `loadingTemplate` diff --git a/src/collection.js b/src/collection.js index 175cc1f5..4622165d 100644 --- a/src/collection.js +++ b/src/collection.js @@ -388,7 +388,13 @@ Thorax.CollectionView = Thorax.View.extend({ if (this.itemTemplate) { viewOptions.template = this.itemTemplate; } - return Thorax.Util.getViewInstance(this.itemView, viewOptions); + if (!this.itemAttributes) { + this.itemAttributes = {}; + } + + var itemAttributes = _.defaults(this.itemAttributes, viewOptions); + + return Thorax.Util.getViewInstance(this.itemView, itemAttributes); } else { // Using call here to avoid v8 prototype inline optimization bug that helper views // expose under Android 4.3 (at minimum) From 6f9108bbb811d09154fbe2c1bb3287e8c8c22227 Mon Sep 17 00:00:00 2001 From: Lior Chen Date: Sun, 14 Sep 2014 15:26:01 +0300 Subject: [PATCH 2/2] changed _.defaults to _.extend --- src/collection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/collection.js b/src/collection.js index 4622165d..55dd2074 100644 --- a/src/collection.js +++ b/src/collection.js @@ -392,7 +392,7 @@ Thorax.CollectionView = Thorax.View.extend({ this.itemAttributes = {}; } - var itemAttributes = _.defaults(this.itemAttributes, viewOptions); + var itemAttributes = _.extend(this.itemAttributes, viewOptions); return Thorax.Util.getViewInstance(this.itemView, itemAttributes); } else {