PDA

View Full Version : Bind to nested data / cascading comboboxes



Vitaliy.Pianykh
22 Mar 2016, 1:45 AM
Hello all,

I have nested models like here:



// define the User model
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['id', 'name', 'age', 'gender'],
validations: [
{type: 'presence', name: 'name'},
{type: 'length', name: 'name', min: 5},
{type: 'format', name: 'age', matcher: /\d+/},
{type: 'inclusion', name: 'gender', list: ['male', 'female']},
{type: 'exclusion', name: 'name', list: ['admin']}
],


proxy: {
type: 'rest',
url : 'data/users',
reader: {
type: 'json',
root: 'users'
}
},


hasMany: 'Post' // shorthand for {model: 'Post', name: 'posts'}
});


//define the Post model
Ext.define('Post', {
extend: 'Ext.data.Model',
fields: ['id', 'user_id', 'title', 'body'],


proxy: {
type: 'rest',
url : 'data/posts',
reader: {
type: 'json',
root: 'posts'
}
},
belongsTo: 'User',
hasMany: {model: 'Comment', name: 'comments'}
});


//define the Comment model
Ext.define('Comment', {
extend: 'Ext.data.Model',
fields: ['id', 'post_id', 'name', 'message'],


belongsTo: 'Post'
});


I need to display three combo-boxes: User, Post, Comment. The combo-boxes should be in the master-detail relationship (cascading). I haven't found any information on how to do it. Any ideas?