Extjs4.0.7 treepanel中定义自定义字段

自定义treePanel 字段,在保留原有的基础上加入自己的字段,便于根据菜单选项,对应响应的处理,网上只说原理没有实例,经过吐血研究终于搞定。注意下版本,版本不同也会有少许不同的(本文版本extjs4.0.7)

 

原理:要自定义tree model 结构,在树数据中带有自定义的字段值时需要在model中指定

 

定义部分:

    Ext.regModel('menuInfo', {

        fields: [
                    { name: 'id', type: 'string', defaultValue: null },
                    { name: 'text', type: 'string', defaultValue: null },
                    { name: 'parentId', type: 'string', defaultValue: null },
                    { name: 'index', type: 'int', defaultValue: null },
                    { name: 'depth', type: 'int', defaultValue: 0 },
                    { name: 'expanded', type: 'bool', defaultValue: false },
                    { name: 'expandable', type: 'bool', defaultValue: true },
                    { name: 'checked', type: 'auto', defaultValue: null },
                    { name: 'leaf', type: 'bool', defaultValue: false },
                    { name: 'cls', type: 'string', defaultValue: null },
                    { name: 'iconCls', type: 'string', defaultValue: null },
                    { name: 'icon', type: 'string', defaultValue: null },
                    { name: 'root', type: 'boolean', defaultValue: false },
                    { name: 'isLast', type: 'boolean', defaultValue: false },
                    { name: 'isFirst', type: 'boolean', defaultValue: false },
                    { name: 'allowDrop', type: 'boolean', defaultValue: true },
                    { name: 'allowDrag', type: 'boolean', defaultValue: true },
                    { name: 'loaded', type: 'boolean', defaultValue: false },
                    { name: 'loading', type: 'boolean', defaultValue: false },
                    { name: 'href', type: 'string', defaultValue: null },
                    { name: 'hrefTarget', type: 'string', defaultValue: null },
                    { name: 'qtip', type: 'string', defaultValue: null },
                    { name: 'qtitle', type: 'string', defaultValue: null },
                    { name: 'formid', type: 'string', defaultValue: null },                  //自定义
                    { name: 'formcode', type: 'string', defaultValue: null },            //自定义
                    { name: 'formname', type: 'string', defaultValue: null },          //自定义
                    { name: 'webpath', type: 'string', defaultValue: null },             //自定义
                    { name: 'exefile', type: 'string', defaultValue: null },                 //自定义
                    { name: 'tcode', type: 'string', defaultValue: null }                   //自定义
            ]
    });

    var treeStore1 = Ext.create('Ext.data.TreeStore', {
         model: 'menuInfo',                                                       //必须的
        autoLoad : true,
        proxy: {
            type: 'ajax',
            url: 'ashx/GetOATreeJson.ashx'    
        },
        /////nodeParam : "FormID",
        root: {
            nodeType: 'async',
            text: 'Erp管理菜单',
            id: '00',
            expanded: true
        }
    });

调用:

       。。。。。

        listeners: {
            'itemclick': function (view, record) {
                    var leaf = record.get('leaf');
                    if (leaf) {
                        var id = record.get('id');
                        var text = record.get('text');
                        var tabPanel = Ext.getCmp('MAINPANEL');
                        addTab2(record.get('text'), record.get('webpath'));   //看看可以获得自定义内容了。。。。
                    }
                    else {
                        //alert('not leaf!');
                        var expand = record.get('expanded')
                        if (expand) {
                            view.collapse(record);
                        }
                        else {
                            view.expand(record);
                    }
                }
            }
        }  //listeners -------funcation end----------
   。。。。    

你可能感兴趣的:(ext,自定义字段,TreePanel)