2013-08-01 3 views
0

Extjs 4를 사용하여 체크 트리가 있는데 문제가 있습니다. 내 트리를 30 초마다 다시로드하고 특정 노드 만 다시로드합니다. 체크 노드 다시 선택 저장 재로드 후 트리 그리드

My Check Tree grid

내가 다시로드 스토어 확인 후, 트리에서 체크 박스에 체크

var node = this.getMyDeviceTree().store.getNodeById('myTree/107'); 
this.getMyDeviceTree().store.load({ node: node }); 

는 선택 해제 할 수 있었다. 저장소를 다시로드 한 후 선택한 노드를 어떻게 기억할 수 있습니까 ??

보기 :

Ext.define('App.view.TreeDeviceStatus', { 
    extend: 'Ext.tree.Panel', 
    store: 'TreeDeviceStore', 
    rootVisible: false, 
    initComponent: function() { 
     var me = this; 

     Ext.applyIf(me, { 
      columns: [{ 
        //treecolumn xtype tells the Grid which column will show the tree 
        xtype: 'treecolumn', 
        text: 'Biển số', 
        width: 140, 
        sortable: true, 
        dataIndex: 'text' 
       }, { 
        text: 'Trạng thái', 
        width: 80, 
        sortable: true, 
        dataIndex: 'Status', 
       }, { 
        text: 'Địa chỉ', 
        width: 250, 
        sortable: true, 
        dataIndex: 'Addr' 
       }] 
     }); 
     me.callParent(arguments); 
    } 
}); 

스토어 :

Ext.define('App.store.TreeDeviceStore', { 
    extend: 'Ext.data.TreeStore', 
    model: 'App.model.DeviceStatusModel', 
    constructor: function(cfg) { 
     var me = this; 
     cfg = cfg || {}; 
     me.callParent([Ext.apply({ 
      proxy: { 
       type: 'ajax', 
       url: '/Service/GetData', 
       extraParams: { 
        serviceName: 'DeviceService', 
        func: 'getStatus', 
        variable: '{"_UserID":"' + _USERID + '","_RoleID":"' + _ROLEID + '"}' 
       }, 
      } 
     }, cfg)]); 
    }, 
    root: { 
     id: 'myTree', 
     //expanded: true 
    }, 
    listeners: { 
     load: function(tree, node, records) { 
      if (node.get('checked')) { 
       node.eachChild(function(childNode) { 
        childNode.set('checked', true); 
       }); 
      } 
     } 
    } 
}); 

고마워!

답변

1

한 번에 하나의 노드에서만로드하는 경우이 노드에서 상태를 복원하는 것이 좋습니다. 그래서로드 된 노드를 알고있는 함수에서이를 수행 할 것입니다. 그 때 그 때와 같을 것입니다 :

function() { 
    var store = tree.getStore(), 
     node = store.getNodeById('myTree/107'), // that's up to you here 
     ids = []; 

    function pluckCheckedIds(node) { 
     if (node.get('checked')) { 
      ids.push(node.getId()); 
     } 
     node.eachChild(function(node) { 
      pluckCheckedIds(node); 
     }); 
    } 

    // EDIT: forgot this line: 
    pluckCheckedIds(node); 

    // EDIT2: in order to save and restore the checked state for the whole 
    // tree (in order to load multiple nodes at once), you could use this 
    // line instead: 
    pluckCheckedIds(store.getRootNode()); 

    store.load({ 
     node: node, 
     callback: function(records, operation) { 
      if (operation.wasSuccessful) { 
       Ext.each(ids, function(id) { 
        var node = store.getNodeById(id); 
        if (node) { 
         node.set('checked', true); 
        } 
       }); 
      } 
     } 
    }); 
} 
+0

안녕하세요 ... 대단히 감사합니다 .. 내가 한 :) 한 번에 여러 노드를 다시로드하고 싶습니다. 다른 방법이 있습니까? –

+0

업데이트 된 (고정 된) 코드를 확인하십시오. 작동시킬 수 있습니까? – rixo