Reputation: 12215
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?
Upvotes: 0
Views: 215
Reputation: 196
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.
Upvotes: 1