Sencha treepanel에서 선택된 row 정보 가져오기

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

treepanel에서 정보를 가져옴

// Assuming 'treePanel' is the reference to your TreePanel instance
var selectedNodes = treePanel.getSelectionModel().getSelection();

// Iterate through the selected nodes
selectedNodes.forEach(function(node) {
    console.log('Selected Node:', node.get('text')); // Replace 'text' with the field name you want
});
Ext.create('Ext.tree.Panel', {
    title: 'Sample TreePanel',
    width: 400,
    height: 300,
    renderTo: Ext.getBody(),
    rootVisible: false,
    store: {
        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 }
                ]}
            ]
        }
    },
    listeners: {
        itemclick: function (view, record) {
            console.log('Selected Node:', record.get('text'));
        },
        selectionchange: function (model, selected) {
            selected.forEach(function (node) {
                console.log('Selected during selection change:', node.get('text'));
            });
        }
    }
});

store에서 정보를 가져옴

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

// Function to check and collect selected nodes
var selectedNodes = [];
store.each(function(record) {
    if (record.get('checked')) { // Check for a specific selection state (like checkbox selection)
        selectedNodes.push(record);
    }
});

// Log the selected nodes
selectedNodes.forEach(function(node) {
    console.log('Selected Node:', node.get('text')); // Replace 'text' with the desired field
});