Reputation: 559
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?
Upvotes: 1
Views: 756
Reputation: 21
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
Upvotes: 1
Reputation: 321
Try to set the types of your schema fields, something like:
schema:{
name: {type:'Text'},
description: {type:'TextArea'},
partition: {type:'Text'},
addresses:[{type:'Object', subSchema:{
address:{type:'Text'},
description:{type:'TextArea'}
}}]
}
Upvotes: 0