TreePanel treestore 加载问题

1:store重复加载

  a:返回数据格式
    在store中的proxy 可能是已下格式 :
           proxy: {
             type: 'ajax',
             url: 'system/Klass/find',
             reader: {
                 type: 'json',
                 root: 'data'
             }
         }
  {"success":true,"data":[{"id":"2","description":"1B"},{"id":"4","description":"1A"}]}

   但treestore 的格式是: 
         proxy:{
             type:'ajax',
             url:'system/Role/loadRole',
            reader:{
                 type: 'json'
            }
          },
       root: {
            loaded: true
        }

     [{"id":"2","description":"1B","left":true,"checked":true},
      {"id":"4","description":"1A",“expanded”:true,
      "children":[{...},{...}]}
      ]

checked : 设置node复选框
expanded : 设置节点展开状态

树复选框展开

2:treestore 自动加载(或禁用自动加载方法)

  autoLoad:在treestore 中无效
 应该设置
 root: {
     loaded: true
 }
  控制treestore 不自动加载数据

3:例子


MVC View

          {
        xtype:'treepanel',
        region:'center',
        style:'margin-top:10px;',
        header:false,
        rootVisible: false,
        useArrows : true,
        border : false,
        autoScroll:true,
        store:Ext.create('Ext.data.TreeStore',{
            fields:['id','text','iconCls'],
            proxy:{
                type:'ajax',
                url:'system/Role/loadRole',
                reader:{
                     type: 'json'
                }
            },
            root: {
               loaded: true
            }
        })
    }

MVC Controller

    Ext.define('App.controller.system.role', {
      extend: 'Ext.app.Controller',
      views: ['system.role'],
      refs: [{
        ref: 'role',
        selector: 'role'
      }],    
    init:function() {
        this.control({
        'role treepanel':{
            checkchange:function( node, checked, eOpts ){
                if(!node.raw.leaf){
                    var nodes = node.childNodes;
                    if (nodes && nodes.length) { 
                        for (var i = 0; i < nodes.length; i++) {  
                            nodes[i].set("checked", checked); 
                        } 
                    }
                }
            },
            afterrender:function(treepanel){
                var store = treepanel.getStore();
                Ext.MessageBox.wait("加载数据中...","温馨提示");
                store.load({
                       callback:function(records){
                            Ext.MessageBox.hide();
                        }
                 });
            }
        }
      });
  }
});

你可能感兴趣的:(TreePanel treestore 加载问题)