PDA

View Full Version : Load form with model with relationship



nivk
28 Jan 2013, 7:00 AM
Hi,

I have this .JSON file.

id:1,
phone:
{
characteristic: 21,
number_part1: 21,
number_part2: 54
}

I have a model customer:


Ext.define('MyApp.model.customer', {
extend: 'Ext.data.Model',

uses: [
'MyApp.model.phone'
],

fields: [
{
name: 'id',
{
name: 'phone'
}
],



hasOne: {
model: 'MyApp.model.phone'
}
});

and a model phone:


Ext.define('MyApp.model.phone', {
extend: 'Ext.data.Model',

fields: [
{
name: 'characteristic'
},
{
name: 'number_part1'
},
{
name: 'number_part2'
}
]
});

I created a form with 4 text fields. I am trying to fill them with the values from the JSON. Using this code at the launch:

var customers = Ext.getStore('s_customers');
customers.filter(1, queryString.cid);
var customer = customers.getAt(0);
Ext.getCmp('personaldetailsForm').getForm().loadRecord(customer);

alert(customer.get('phone').characteristic); //This correctly shows the alert with the value 21

The problem is that only the text field with id is correctly filled. The others won't work. How do I have to bind the other text fields with data from the model? Is ok to use "name: 'phone.characteristic'"? The relationship that I've created is wrong?

{
xtype: 'textfield',
flex: 1,
margin: '0 10 0 0',
name: 'phone.characteristic'
}

Thanks in advance.

nivk
28 Jan 2013, 7:23 PM
Please help :-|

nivk
30 Jan 2013, 10:57 PM
Hello, I still trying to do this, does someone knows how to do it?

Thanks!!

castitas
15 Feb 2013, 3:50 PM
Do you have the code for your form? I think you have to put a name on the form items.