Skip to content
Browse files

Fix "foreach" binding so it doesn't attempt to apply child bindings t…

…o nonbindable nodes (e.g., text nodes)
  • Loading branch information...
1 parent 8076f8d commit 94315542c341d64fec6fb5f80bcc6c5349dc84f0 @SteveSanderson SteveSanderson committed May 21, 2011
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/binding/defaultBindings.js
View
6 src/binding/defaultBindings.js
@@ -460,8 +460,10 @@ ko.bindingHandlers['foreach'] = {
var mapping = function(arrayEntry) {
var nodeArray = ko.utils.parseHtmlFragment(options['dataStore'].foreachHtml);
- for (var i = 0, j = nodeArray.length; i < j; i++)
- ko.applyBindings(arrayEntry, nodeArray[i], { 'extraScope': { '$data': arrayEntry } });
+ for (var i = 0, j = nodeArray.length; i < j; i++) {
+ if (nodeArray[i].nodeType == 1)
+ ko.applyBindings(arrayEntry, nodeArray[i], { 'extraScope': { '$data': arrayEntry } });
+ }
return nodeArray;
};
ko.utils.setDomNodeChildrenFromArrayMapping(element, filteredArray, mapping, { 'afterAdd': bindingValue['afterAdd'], 'beforeRemove': bindingValue['beforeRemove'] });

0 comments on commit 9431554

Please sign in to comment.
Something went wrong with that request. Please try again.