Hybrid View

  1. #1
    Sencha User
    Join Date
    Jan 2013
    Posts
    9
    Vote Rating
    0
    nivk is on a distinguished road

      0  

    Default Unanswered: Load form with model with relationship

    Unanswered: Load form with model with relationship


    Hi,

    I have this .JSON file.

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

    I have a model customer:

    Code:
    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:

    Code:
    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.

  2. #2
    Sencha User
    Join Date
    Jan 2013
    Posts
    9
    Vote Rating
    0
    nivk is on a distinguished road

      0  

    Default


    Please help

  3. #3
    Sencha User
    Join Date
    Jan 2013
    Posts
    9
    Vote Rating
    0
    nivk is on a distinguished road

      0  

    Default


    Hello, I still trying to do this, does someone knows how to do it?

    Thanks!!

  4. #4
    Sencha User castitas's Avatar
    Join Date
    Sep 2011
    Location
    US
    Posts
    116
    Answers
    3
    Vote Rating
    3
    castitas is on a distinguished road

      0  

    Default


    Do you have the code for your form? I think you have to put a name on the form items.
    word

Thread Participants: 1

Tags for this Thread