Arrays of objects in the Backbone form

advertisements

I am using backbone forms for my current project and I am finding difficulties with creating the schema for Arrays,

 schema:{
        name:{},
        description:{},
        partition:{},
        'addresses':[{type:'Object',subSchema:{address:{}, description:{}}}]

    }

this is my schema

 var obj = {
                name:'suchita',
                description:'device3 desc',
                partition:'346',
                'addresses':
                    [{address:'abc', description:'xyz'}]

            };

           var user=new Model(obj);

and this is where I fill the schema. Now my api wants me to send an array of "addresses" object i.e

addresses: 0: {address:'abc',description:'xyz'} 1: {address:'uio',description:'uiyui'}

but somehow it doesn't happen in this way. Can you help me in where am I going wrong?


I know it's late but I think the syntax with a list is something like:

schema:{
    name:{},
    description:{},
    partition:{},
    addresses: {type:'List',itemType: 'Object',
        subSchema:{
            address:{},
            description:{}
        }
    }
}

Of course you have to include the List editor for backbone-forms:

<script src="backbone-forms/distribution/editors/list.min.js"></script>

And you can fill in with:

var obj = { addresses: [
    {
        address: 'my address',
        description: 'home'
    }
]};

var user = new Model(obj);

I haven't checked if this works but I have a similar case in my code so it should work