Sencha treepanel의 모든 node 펼치기

2024. 12. 5. 16:38Javascript/Sencha

treepanel의 함수 사용

var treePanel = Ext.ComponentQuery.query('treepanel')[0]; // Get your TreePanel instance
if (treePanel) {
    treePanel.expandAll(); // Expand all nodes
    console.log('All nodes have been expanded.');
}

store를 이용

var treePanel = Ext.ComponentQuery.query('treepanel')[0]; // Get your TreePanel instance
var store = treePanel.getStore(); // Get the TreeStore

store.getRootNode().cascadeBy(function (node) {
    node.set('expanded', true); // Set each node's expanded property to true
});

console.log('All nodes have been expanded manually.');

loading시 처리

var store = Ext.create('Ext.data.TreeStore', {
    root: {
        expanded: true,
        children: [
            { text: 'Node 1', leaf: true },
            { text: 'Node 2', leaf: true },
            { text: 'Folder', expanded: true, children: [
                { text: 'SubNode 1', leaf: true },
                { text: 'SubNode 2', leaf: true }
            ]}
        ]
    }
});