I am retrieving a json object from the server and populating my view. Then I change the data, push it to the server. Then I retrieve a new copy of the data, hoping that it will update my view with any changes. However, this does not happen. TIA
$(document).ready(function() { var customer_id = get_customer_id(); var data = load_model(); contract_model = ko.mapping.fromJS(data,{}); ko.applyBindings(contract_model); } function load_model(){ var url = '/ar/contract_json?contract_id='+get_contract_id(); var data = ''; $.ajax({ type:'GET', url:url, async:false, success: function(returningValue){ data = returningValue; } }); return data; }
This boot is working fine. Then I do some things and change one of the observed ones and drop the data to the server. The server receives the update, and then I make a new selection of data, so that the view will be updated (I know that I can transfer new data in one step, but this is in code that has not yet been reorganized).
function refresh_data(contract_model){ var url = '/ar/contract_json?contract_id='+get_contract_id(); $.post(url,function(data){ console.log(data); ko.mapping.fromJS(contract_model,{},data); ko.applyBindings(contract_model); console.log(ko.mapping.toJS(contract_model)) }); } function refresh_data(contract_model){ var url = '/ar/contract_json?contract_id='+get_contract_id(); $.post(url,function(data){ console.log(data); ko.mapping.fromJS(contract_model,{},data); console.log(ko.mapping.toJS(contract_model)) }); } function push_model(contract_model,refresh){ var url = '/ar/update_contract'; var data = {'contract':ko.mapping.toJSON(contract_model)} delete data['lines']; $.post(url,data,function(return_value){ if (refresh){ refresh_data(contract_model); }; }); }
All console messages show new data, but my view is never updated.
source share