Question

I make the following json client side:

{
    "employees": [
        {
            "firstName": "John",
            "lastName": "Doe",
            "computers": [
                {
                    "name": "comp1"
                },
                {
                    "name": "comp2"
                }
            ]
        },
        {
            "firstName": "Anna",
            "lastName": "Smith",
            "computers": [
                {
                    "name": "comp1"
                },
                {
                    "name": "comp2"
                }
            ]
        },
        {
            "firstName": "Peter",
            "lastName": "Jones",
            "computers": [
                {
                    "name": "comp1"
                },
                {
                    "name": "comp2"
                }
            ]
        }
    ]
}

And I would like to stick it into this model:

Ext.define('Employees',{
  extend: 'Ext.data.Model',
  hasMany: [{
    model: 'Computers',
    name: 'computers',
  }],
  fields: [{name: 'firstname'}, {name: 'lastname'}]
});

Ext.define('Computers'{
  extend: 'Ext.data.Model',
  belongsTo: 'Employees',
  fields: [{name: 'name'}]
});

How can I convert the json into my Employees extjs model?

Was it helpful?

Solution

You should have to define a data store like this:

Ext.create('Ext.data.Store', {
    model: 'Employees',
    storeId: 'myDataStore',
    proxy: {
            type: 'ajax',
            url : 'path/to/your/json/file/Employees.json',
            reader:{ 
                type:'json',
                root: 'employees'
            }
        }
});

and load it somewhere.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top