javascript - knockout custom select binder with update function -
i trying develop custom select binder not able understand how develop update functionality. this have done. want custom binder handle type of data
[{ message: "hello", value: 1 }, { message: "hi", value: 2 }, { message: "bye", value: 3 }, ]
the problem, understand it: using bootstrap fullscreen select, , can initialize it, when select new value, no observable gets updated. basically, need know when new value selected.
since way widget works pop screen of options , allow select one, , close popup, and widget provides ability onclose
callback, that's need.
i'm using standard convention of value
binding in select. when widget closes, if new value different bound value, update bound value new value selected in widget.
ko.bindinghandlers.menu = { init: function (element, valueaccessor, allbindingsaccessor, viewmodel) { var valueobservable = allbindingsaccessor().value; $(element).mobileselect({ onclose: function () { var newvalue = $(this).val(); if (newvalue !== valueobservable()) { valueobservable(newvalue); } } }); } };
as fiddle: http://jsfiddle.net/4zsu9pv2/4/
Comments
Post a Comment