Is there any performance or other profit using custom binding and $ .on () to respond to human interactions with some list of data with ~ 500 rows?
This question came to my mind because I noticed that knockout events are bound to an element using bind (), does that mean they are on every button, or am I mistaken?
I have two samples
First http://jsfiddle.net/dzjosjusuns/yStt7/ - an event attached to a child
<div data-bind="text:head.id"></div> <div id="container" data-bind="foreach:head.rows"> <div class="item"> <button data-bind="click:$root.head.deleteRow">remove</button> <span data-bind="text:name"></span> </div> </div>
The second - http://jsfiddle.net/dzjosjusuns/NN3h8/ - the event is bound to the parent object only with user binding
<div data-bind="text:head.id"></div> <div id="container" data-bind="foreach:head.rows, onRowDelete:head.deleteRow"> <div class="item"> <button>remove</button> <span data-bind="text:name"></span> </div> </div>
Binding custome
ko.bindingHandlers.onRowDelete = { init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { $('#container').on('click', '.item button', function (event) { valueAccessor().call(viewModel.head, ko.dataFor(event.target), event.target); }); } };
So, does it make sense to do such custom bindings?
source share