javascript - How to et Knockout JS update the UI by changing Model property -
i new knockout, assume should allow alter ui automatically changing js model property please have code on jsfiddle
http://jsfiddle.net/jt6bbeq4/2/
and tell me missing? update link should update property name , so, auto update span text "bob" "tedd"
html:
<a href='#' data-bind="click: update">update name</a><br/> <span data-bind="text: name"></span>
viewmodel:
var viewmodel = function () { var self = this; self.name = ko.observable('bob'); self.update = function () { this.name = 'tedd'; } }; var vm = new viewmodel(); ko.applybindings(vm);
you need update observable, not replace it:
this.name = 'tedd'; // <-- observable replaced string this.name('tedd'); // <-- value of observable replaced new value
so should be:
self.update = function () { self.name('tedd'); }
http://jsfiddle.net/jt6bbeq4/3/
javascript jquery knockout.js
No comments:
Post a Comment