Posts

Showing posts from March, 2015

knockout.js "data-" attribute binding handler

Gist: https://gist.github.com/dirnthelord/ca0fcbb25c7f0bea8e03

ko.bindingHandlers.data= { name: ko.observable(''), update: function (element, valueAccessor, allBindingsAccessor) { var va = ko.utils.unwrapObservable(valueAccessor()); var value ="", name =""; var d = {}; if (typeof (va) ==="object") { for (var k in va) { var _val = ko.utils.unwrapObservable(va[k]); if (typeof (_val) !=="object") { d["data-"+ k] = _val; } else { d["data-"+ k] = ko.toJSON(_val); } } } else { value = va; name = ko.utils.unwrapObservable(allBindingsAccessor().name!==undefined ? allBindingsAccessor().name