Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: g.pushFromModel is not a function #61

Open
pietvis opened this issue Jun 10, 2014 · 4 comments
Open

TypeError: g.pushFromModel is not a function #61

pietvis opened this issue Jun 10, 2014 · 4 comments

Comments

@pietvis
Copy link

pietvis commented Jun 10, 2014

I have an issue in which I get the message "TypeError: g.pushFromModel is not a function". This happens when I call ko.viewmodel.updateFromModel for the second time. The code is as follows:

viewModel = {
    lists: null
};

var koViewModel = ko.viewmodel.fromModel(viewModel, {
    extend: {
        "{root}": function (model) {
            model.selectedList = ko.observable(null);
            model.isOnLine = ko.observable(false);
            model.selectList = function (list) {
                model.selectedList(list);
            };
            model.addList = function (list) {
                model.lists.push(list);
            };
            model.removeList = function (list) {
                model.lists.remove(list);
            };
        }
    });
// Mind that viewModel.lists = null which is correct, no data here.
ko.applyBindings(koViewModel );

// Load data from the cache, this goes well. Data is presented on the screen.
viewModel.lists = JSON.parse(jsonCache);
ko.viewmodel.updateFromModel(koViewModel, viewModel);

// Load data from the server and update "cached" data
viewModel.lists = [data from server, which is correct (identical to cached)];
ko.viewmodel.updateFromModel(koViewModel, viewModel);

The last line gives me the error "TypeError: g.pushFromModel is not a function". In fact, when I call the function
ko.viewmodel.updateFromModel(koViewModel, viewModel);
twice in the first section, I get the message as well.

@Devqon
Copy link

Devqon commented May 8, 2015

Have you found a solution for this? I'm hitting exactly the same issue.

@DjCzermino
Copy link

I have same problem, any solution?

@enispilavdzic
Copy link

same here, anyone know if this project is still being actively maintained?

@enispilavdzic
Copy link

enispilavdzic commented Jun 17, 2016

It seems if the data being updated does not exactly match the structure you have, for example if you try to update an observablearray with a string, that causes this error.

In my case data coming from server was a string and I forgot to turn it into JSON first like:

var dataFromServer = ko.utils.parseJson(JSONdataFromServer);

before

ko.viewmodel.updateFromModel(koViewModel, viewModel);

After I added that error went away and it worked. Hope that helps others with this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants