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

Mapping not saved when data is an array #202

Open
jt000 opened this issue Nov 18, 2014 · 1 comment
Open

Mapping not saved when data is an array #202

jt000 opened this issue Nov 18, 2014 · 1 comment

Comments

@jt000
Copy link

jt000 commented Nov 18, 2014

The problem is that when using ko.mapping for a single object the mapping is retained for later use:

    var mapping = {
        id: { create: function(o) { return 'ID#'+o; } },
    };

    var datum = {id: 500};
    var datumVm = ko.mapping.fromJS(datum, mapping);
    // ko.mapping.isMapped(datumVm) is defined

However, when using ko.mapping to map an array, the mapping isn't saved which prevents hiding of added values:

    var mapping = {
        id: { create: function(o) { return 'ID#'+o; } },
    };

    var data = [{id: 500}, {id:499}];
    var dataVm = ko.mapping.fromJS(data, mapping);
    // ko.mapping.isMapped(dataVm) is NOT defined

Here is a fiddle demonstrating the issue: http://jsfiddle.net/vkd3nefa/1/

@jt000
Copy link
Author

jt000 commented Nov 18, 2014

Note that if I setting __ko_mapping__ on each element in the VM's array, then this does work properly:
see http://jsfiddle.net/vkd3nefa/2/ for example

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

1 participant