I would like to build a custom bindingHandler
ko.bindingHandlers.foreachWithHighlight that has an highlight effect when afterAdd.
yellowFadeIn: function(element, index, data) {
$(element).filter("li")
.animate({ backgroundColor: 'yellow' }, 200)
.animate({ backgroundColor: 'white' }, 800);
},
But I want to always add this to my valueAccessor and pass it to the foreach binding.
ko.bindingHandlers.foreachWithHighlight = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, context) {
return ko.bindingHandlers.foreach.init(element, valueAccessor, allBindingsAccessor, viewModel, context);
},
update: function (element, valueAccessor, allBindingsAccessor, viewModel, context) {
var value = ko.unwrap(valueAccessor());
var newValue = function () {
return {
data: value,
afterAdd: function(element, index, data) {
$(element).filter("li")
.animate({ backgroundColor: 'yellow' }, 200)
.animate({ backgroundColor: 'white' }, 800);
}
};
};
return ko.bindingHandlers.foreach.update(element, newValue, allBindingsAccessor, viewModel, context);
}};
How can I prevent it from running the first time when all the nodes from the server is added. I just want it to run when new nodes added.