javascript - Custom Binding Calling Only Once -


after thread, knockoutjs custom binding working, update function working once on clicking same column again. how make call function again ?

after googling found

ko.cleannode(element) 

how apply this? ideas?

here fiddle

you need store state of last sorby , if matches flip sort direction.

see updated fiddle: http://jsfiddle.net/tkirda/nhthh/4/

var lastsortby = ''; var direction = 1;  ko.bindinghandlers.sortfunction = {     update: function(element, valueaccessor, allbindingsaccessor, viewmodel) {         var sortby = ko.utils.unwrapobservable(valueaccessor());         var items = viewmodel.items;         $(element).unbind('click.sort').bind('click.sort', function() {             if (lastsortby === sortby){                 direction = direction === 1 ? -1 : 1;             } else {                 direction = 1;             }             lastsortby = sortby;             items.sort(function(a, b) {                 return direction * (a[sortby]() < b[sortby]() ? -1 : 1);             });         });     } } 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -