I'm trying to understand the new association concept in Extjs 5 data models.
I've got the following models
// User
Ext.define('App.model.User', {
extend: 'App.model.Base',
fields: [
{name: 'id', type: 'string'},
{name: 'name', type: 'string'},
],
manyToMany: {
Categories: {
type: 'Categories',
role: 'categories',
field: 'categories',
right: true
}
}
});
// Category
Ext.define('App.model.Category', {
extend: 'App.model.Base',
constructor: function () {...},
fields: [
{name: 'id', type: 'string'},
{name: 'categoryName', type: 'string'},
]
});
I've got the following json for a user:
{ "user": { "id": "1", "name": "Foo", "categories": [1, 2, 3] } }
When the User
model is loaded it should initialize the categories store with the data.
(My Category
model knows to convert the number to a object of id & categoryName)
For some reason when I try getting the users' categories the store is empty.
userRecord.categories(); // has no records
How can I get this to work?
There are two main types of Proxy - Ext.
You can look at requires as a way to tell ExtJS: "When you construct an object of this class, please make sure to dynamically load the required scripts first".
The Ext namespace (global object) encapsulates all classes, singletons, and utility methods provided by Sencha's libraries.
The controller (Ext. app. Controller) in ExtJS 4. x is used to handle events from multiple components using CSS-like selectors to match components and respond to their events.
Please try it
// User
Ext.define('User', {
extend: 'app.data.Model',
fields: [
{name: 'id', type: 'string'},
{name: 'name', type: 'string'},
],
hasMany: {
Categories: {
type: 'Categories',
role: 'categories',
field: 'categories',
right: true
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With