0

使用 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");
    }
}
...

任何有关如何在此处获取子记录的见解将不胜感激。

4

1 回答 1

0

我对你想要什么有点困惑,但我认为就是这样:

listeners: {
    select: function(rowModel, record){
    console.log(record.get("category"));
    }
}
于 2012-09-07T13:26:50.650 回答