javascript - KnockoutJS IF binding - keep DOM -
the if
binding removes dom , stops executing inner data-bind
attributes if condition false
.
is possible keep dom when condition false
? want stop executing data-bind
when condition false
not wish remove dom due jquery bindings etc.
i came following solution delays knockout binding application until condition satisfied.
it not remove binding when condition becomes false
not necessary in case.
ko.bindinghandlers['applywhen'] = { init: function() { return { controlsdescendantbindings: true }; }, update: function(element, valueaccessor, allbindings, model, bindingcontext) { if (!element.bindingapplied && boolean(ko.unwrap(valueaccessor()))) { element.bindingapplied = true; ko.applybindingstodescendants(bindingcontext, element); } } };
Comments
Post a Comment