Permalink
Browse files

Add support for creating child context if item == '$data'

This requires support in Knockout for observable child contexts (knockout/knockout#485), which is currently only available in my Knockout smart-binding fork (https://github.com/mbest/knockout)
  • Loading branch information...
1 parent e77dc4f commit 2521fd45dd97f663f2e9ba53af0a718e18c41019 @mbest committed Jun 22, 2012
Showing with 110 additions and 101 deletions.
  1. +9 −3 knockout-repeat.js
  2. +0 −97 spec/lib/knockout-2.0.0.js
  3. +87 −0 spec/lib/knockout-2.1.0-mbest-smart-binding-beta.6.js
  4. +13 −0 spec/repeatBinding.js
  5. +1 −1 spec/runner.html
View
@@ -85,10 +85,16 @@ ko.bindingHandlers['repeat'] = {
newNode.setAttribute('data-repeat-index', lastRepeatCount);
// Apply bindings to inserted node
- var newContext = ko.utils.extend(new bindingContext.constructor(), bindingContext);
+ if (repeatArray && repeatData == '$data') {
+ var newContext = bindingContext.createChildContext(makeArrayItemAccessor(lastRepeatCount));
+ } else {
+ var newContext = bindingContext.extend
+ ? bindingContext.extend()
+ : ko.utils.extend(new bindingContext.constructor(), bindingContext);
+ if (repeatArray)
+ newContext[repeatData] = makeArrayItemAccessor(lastRepeatCount);
+ }
newContext[repeatIndex] = lastRepeatCount;
- if (repeatArray)
- newContext[repeatData] = makeArrayItemAccessor(lastRepeatCount);
ko.applyBindings(newContext, newNode);
}
}, null, {'disposeWhenNodeIsRemoved': placeholder});
Oops, something went wrong.

0 comments on commit 2521fd4

Please sign in to comment.