I am trying to present several selections with selected values from the JSON backend to the knockout representation model. And it was necessary to restore this JSON when each choice was changed, the first time everything was fine, but if I applied the mapping again (ko.mapping.fromJS (test_data, ViewModel)), all subscriptions are lost, does anyone know how to avoid this situation?
jsfiddle (I don’t know why selects does not have its own values, without jsfiddle everything is fine): http://jsfiddle.net/0bww2apv/2/
$(ViewModel.attributes()).each(function(index, attribute) { attribute.attribute_value.subscribe(function(name) { console.log('SUBSCRIBE', name); var send_data = {}; $(ViewModel.attributes()).each(function (index, attribute) { send_data[attribute.attribute_name.peek()] = attribute.attribute_value.peek(); if (attribute.attribute_value() === null) { send_data = null; return false; } }); if (send_data) { console.log('REQUEST TO BACKEND: ', ko.toJSON(send_data)); ko.mapping.fromJS(test_data, ViewModel);
source share