My KnockoutJS template looks as follows:
<div id="wrapper" data-bind="template: {
name:'theTemplate',
foreach: cars(),
beforeRemove: function(elem) {
console.log(elem);
console.log('try removing..');
try {
jQuery(elem).hide().remove();
} catch (e) {
console.log(e);
}
},
afterAdd: function(elem) {
console.log('try adding..');
try {
jQuery(elem).hide().fadeIn();
} catch (e) {
console.log(e);
}
}
}"></div>
When I'm removing a object from the cars() observableArray I want to hide() and remove() the element which is being removed. Except when removing a element the beforeRemove function is called three times with three different elements as parameter.
The three elements are:
Comment { data=" Block 1 ", length=9, nodeName="#comment", meer...}
try removing..<TextNode textContent=" ">
try removing..<div class="block">
try removing..
The afterAdd behaves the same way.. Is this a bug, or is my understanding of the function incorrect?
Thanks for your time!