asp.net mvc - Knockout JS - one way binding in order to keep server values? -
asp.net mvc - Knockout JS - one way binding in order to keep server values? -
i'm setting form in knockout within mvc application , displaying info database, such as:
@html.editorfor(model => model.addresspostcode) // filled in controller. this fine, expected. however, i've worked lot knockout js , want value used within search of mine (and thus, data-bind="value: postcode" on postcode element.
the problem? well, when bind postcode: ko.observable(''), pre-populated server value gets replaced '' (as you'd expect really). there way around this?
the value binding overriding predefined value, think antipattern utilize both server side mvc , client side mvvm, if want take route need create own binding like
ko.bindinghandlers.valuewithinit = { init: function(element, valueaccessor, allbindingsaccessor, context) { var observable = valueaccessor(); var value = element.value; observable(value); ko.bindinghandlers.value.init(element, valueaccessor, allbindingsaccessor, context); }, update: ko.bindinghandlers.value.update }; asp.net-mvc knockout.js
Comments
Post a Comment