In the example below you'll see that doSomething never fires. If you remove the if: Comments from the templating binding doSomething will fire as expected. Does anyone know what is happening to cause this? This also occurs while using the data attribute on the template binding handler.
I am currently using Knockout 2.2.1. jsfiddle http://jsfiddle.net/YADzx/2/
<div data-bind="template: { if: Comments, name: 'comments' }"></div> <script type="tmpl" id="comments"> <div data-bind="foreach: { data: Comments, afterAdd: $root.doSomething }"> <div data-bind="text: name"></div> </div> </script> <script> var vm = { Comments: ko.observableArray([{name:'hey'}]), doSomething: function (element, index, data) { $(element).addClass('wow'); } }; ko.applyBindings(vm); vm.Comments.push({name:'foo'}); vm.Comments.push({name:'bar'}); </script>