Permalink
Browse files

Prevent binding on text nodes, and workaround IE < 9 issue whereby re…

…moved elements still have a parentNode
  • Loading branch information...
1 parent 6793ec0 commit b78a926c10cf35e63989fc952d9c3f3f8eccfba7 @SteveSanderson SteveSanderson committed Aug 18, 2011
Showing with 4 additions and 4 deletions.
  1. +1 −1 src/binding/bindingAttributeSyntax.js
  2. +3 −3 src/templating/templating.js
@@ -147,7 +147,7 @@
};
ko.applyBindings = function (viewModel, rootNode) {
- if (rootNode && (rootNode.nodeType !== 1) && (rootNode.nodeType !== 3) && (rootNode.nodeType !== 8))
+ if (rootNode && (rootNode.nodeType !== 1) && (rootNode.nodeType !== 8))
throw new Error("ko.applyBindings: first parameter should be your view model; second parameter should be a DOM node");
rootNode = rootNode || window.document.body; // Make "rootNode" parameter optional
applyBindingsToNodeAndDescendantsInternal(viewModel, rootNode, true);
@@ -16,13 +16,13 @@
var nodeArrayClone = ko.utils.arrayPushAll([], nodeArray); // So we can tolerate insertions/deletions during binding
var node;
+ var commonParentElement = (nodeArray.length > 0) ? nodeArray[0].parentNode : null; // All items must be in the same parent, so this is OK
for (var i = 0; node = nodeArrayClone[i]; i++) {
- if (!node.parentNode) // Skip anything that has been removed during binding
+ if (node.parentNode !== commonParentElement) // Skip anything that has been removed during binding
continue;
switch (node.nodeType) {
- case 1: // Elements
- case 3: // Text nodes (can't have bindings, can have a bindingContext associated with them)
+ case 1: // Elements (can have bindings)
case 8: // Comment nodes (may be containerless templates)
ko.applyBindings(bindingContext, node);
ko.memoization.unmemoizeDomNodeAndDescendants(node, [bindingContext]);

0 comments on commit b78a926

Please sign in to comment.