knockoutjs - update via ajax when model property was edited inline
http://stackoverflow.com/questions/20149760/knockout-do-update-in-db-via-ajax-when-model-property-was-edited-via-inline-e
by Naveen Jose
HTML
<p>
Name: <b data-bind="visible: !editing(),
text: name,
click: edit"> </b>
<input data-bind="visible: editing,
value: name,
hasFocus: editing,
event: { blur: myblurFunction }" />
</p>
<p><em>Click the name to edit it; click elsewhere to apply changes.</em></p>
JavaScript
function PersonViewModel(name) {
var self = this;
self.name = ko.observable(name);
self.editing = ko.observable(false);
self.edit = function () {
this.editing(true);
}
this.myblurFunction = function() {
var newName = self.name();
alert("Houston! We have lost focus on " + newName);
// ajax call here.
}
}
ko.applyBindings(new PersonViewModel("Bert Bertington"));