mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
#each .. in extends the data context for children
Regular #each ({{#each items}}) sets a new data context for each child view to
the item of the sequence.
The new #each ({{#each item in items}}) preserves the data context and extends
it to have the variable like 'item'
This commit is contained in:
@@ -112,19 +112,20 @@ Blaze.Each = function (argFunc, contentFunc, elseFunc) {
|
||||
}, {
|
||||
addedAt: function (id, item, index) {
|
||||
Tracker.nonreactive(function () {
|
||||
// create an alias for the data context defined by argFunc.
|
||||
var newDataContext;
|
||||
if (eachView.variableName) {
|
||||
// new-style #each (as in {{#each item in items}})
|
||||
// the new data context is the same but with an extension by
|
||||
// variable name (e.g. 'item')
|
||||
var _item = item;
|
||||
if (! _.isObject(item)) {
|
||||
item = {};
|
||||
} else {
|
||||
item = _.clone(item);
|
||||
}
|
||||
|
||||
item[eachView.variableName] = _item;
|
||||
var dataContext = Blaze.getData(eachView);
|
||||
newDataContext = _.clone(dataContext) || {};
|
||||
newDataContext[eachView.variableName] = item;
|
||||
} else {
|
||||
newDataContext = item;
|
||||
}
|
||||
|
||||
var newItemView = Blaze.With(item, eachView.contentFunc);
|
||||
var newItemView = Blaze.With(newDataContext, eachView.contentFunc);
|
||||
eachView.numItems++;
|
||||
|
||||
if (eachView.expandedValueDep) {
|
||||
|
||||
Reference in New Issue
Block a user