使用ExtJS 4,我已按以下方式定义了两个模型:
Ext.define('GlsAmCrm.model.grpModel',{
extend: 'Ext.data.Model',
idProperty: 'recordid',
fields:[
{name: 'text', type: 'string'},
{name: 'id', type: 'string'},
{name: 'cls', type: 'string'},
{name: 'leaf', type: 'bool'}
],
proxy: {
type: 'ajax',
api:{
create: '/app/data/grpdata.php/create',
read:'/app/data/grpdata.php/read',
update:'/app/data/grpdata.php/update',
destroy:'/app/data/grpdata.php/destroy'
},
reader: {
type: 'json',
root: 'condata',
successProperty: 'success'
}
},
hasMany: {model: 'GlsAmCrm.model.conModel', name: 'condata', associationKey:'condata'}
});
Ext.define('GlsAmCrm.model.conModel',{
extend: 'Ext.data.Model',
idProperty: 'recordid',
fields:[
{name: 'text', type: 'string'},
{name: 'id', type: 'string'},
{name: 'cls', type: 'string'},
{name: 'leaf', type: 'bool'},
{name: 'loaded', type: 'bool'},
{name: 'parentId', type: 'string'},
{name: 'category', type: 'string'}
],
belongsTo: 'GlsAmCrm.model.grpModel'
});
我已使用返回JSON响应将嵌套数据成功加载到树面板中:
{
"condata": [
{
"text": "<span class=\"tree-group\">Arrowleaf Technologies</span>",
"id": "d61c7bb7-dd88-11e1-a355-0013d3f996ae",
"cls": "tree-root",
"leaf": false,
"condata": [
{
"text": "<span class=\"tree-contact\">Dos Santos, Robert A</span>",
"id": "1df08c59-d718-11e1-aa72-0013d3f996ae",
"cls": "tree-root",
"parentId": "d61c7bb7-dd88-11e1-a355-0013d3f996ae",
"leaf": true,
"loaded": true,
"category": "A"
},
{
"text": "<span class=\"tree-contact\">Interrante, Sheila D</span>",
"id": "0d212d01-d718-11e1-aa72-0013d3f996ae",
"cls": "tree-root",
"parentId": "d61c7bb7-dd88-11e1-a355-0013d3f996ae",
"leaf": true,
"loaded": true,
"category": "B"
},
{
"text": "<span class=\"tree-contact\">Sanford, Martha J</span>",
"id": "14e3e4cb-d718-11e1-aa72-0013d3f996ae",
"cls": "tree-root",
"parentId": "d61c7bb7-dd88-11e1-a355-0013d3f996ae",
"leaf": true,
"loaded": true,
"category": "C"
},
{
"text": "<span class=\"tree-contact\">Simmons, Shawn P</span>",
"id": "06354f92-d718-11e1-aa72-0013d3f996ae",
"cls": "tree-root",
"parentId": "d61c7bb7-dd88-11e1-a355-0013d3f996ae",
"leaf": true,
"loaded": true,
"category": "D"
}
]
},
{
"text": "<span class=\"tree-group\">Consolidated Physician Services</span>",
"id": "bba64918-dd87-11e1-a355-0013d3f996ae",
"cls": "tree-root",
"leaf": false
},
{
"text": "<span class=\"tree-group\">Pinellas County Schools</span>",
"id": "ed409413-e947-11e1-a7ed-0016177c526f",
"cls": "tree-root",
"leaf": false
}
]
}
如果我展开第一个条目,我会看到所有的子叶子。如果我点击其中一个子叶(比如Dos Santos,Robert),我想访问该子记录的“类别”字段:
...
listeners: {
newselection: function(view,rec){
console.log ("THIS IS WHERE I NEED HELP");
}
}
...
有关如何抓住儿童记录的任何见解将非常感激。
答案 0 :(得分:0)
我对你想要的东西感到有点困惑,但我认为就是这样:
listeners: {
select: function(rowModel, record){
console.log(record.get("category"));
}
}