knockout.js - Knockout mapping plugin options -


i'm not sure how instruct plugin make not observable specific property of inner array.

take json data:

{     id: 1,     description: "test",     roles: [{ id: 1, name: "role 1" }, { id: 2, name: "role 2" }] } 

the roles array should observable, don't want make observable "id" fields of items, i'm trying differents approaches, no luck:

ko.mapping.fromjs(data, { 'copy': [ "roles.id" ] }); ko.mapping.fromjs(data, { 'copy': [ "roles[].id" ] }); ko.mapping.fromjs(data, { 'copy': [ "roles[0].id" ] }); // works first item 

any ideas?

i don't know if there direct solution problem, tried navigate descendants of roles array none working(like tries) can make simple trick defining model roles item object:

function rolesmodel(id, name) {     this.id = id;     this.name = ko.observable(name); } 

then use mapping configuration control creation of roles object :

var mapping = {     'roles': {         create: function (options) {             return new rolesmodel(options.data.id, options.data.name)         }     } } 

as told don't know direct solution gonna work. kindly check demo


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -