Wednesday, 15 January 2014

knockout.js - KnockoutJS Mapping toJS ignore nested keys -



knockout.js - KnockoutJS Mapping toJS ignore nested keys -

can not ignore nested properties when using tojs in knockoutjs' mapping plugin?

example:

var obj = { "akey": { "anestedkey": "ignore", "anotherkey": "value" } }; console.log(ko.mapping.tojs(obj, { "ignore": ["akey.anestedkey"], }));

expected output

{ akey: { anotherkey: "value" } }

actual output is

{ akey: { anestedkey: "ignore" anotherkey: "value" } }

jsfiddle: http://jsfiddle.net/48kvu/

it works if remove parent (if know key unique in obj or if want remove occurences):

var obj = { "akey": { "anestedkey": "ignore", "anotherkey": "value" } }; console.log(ko.mapping.tojs(obj, { "ignore": ["anestedkey"], //here }));

http://jsfiddle.net/gabrieltran/48kvu/1/

knockout.js knockout-mapping-plugin

No comments:

Post a Comment