1
votes

I am generating the knockout mapping from server side view model using below

    var bindData2ViewModel = function (data) {
        var rdata = ko.toJSON(data);
        ko.mapping.fromJSON(rdata, {}, vm.model());
        ko.applyBindings(vm);
    };

    var CustomerViewModel = function () {
        var self = this;
        self.model = ko.observable({});
        return { model: self.model };
    };

    var vm = new CustomerViewModel();

now there is another call which is giving me the data... i just want to bind that data to the client side viewmodel without changing the binding... how to do that?

    var rebindData2ViewModel = function (data) {
        var rdata = ko.toJSON(data);
        vm.model.set(rdata);
        ko.applyBindings(vm);
    };

tried above but not working... what is the correct way to do this?

1

1 Answers

0
votes

basically to rebind the data to the existing model.. you just need to set the data using the angular brackets.. no need of json etc... because data should itself return as jsonresult

    var rebindData2ViewModel = function (data) {
        vm.model(data);
    };