Sencha grid에 선택된 rows를 서버에 전송하기

2024. 12. 27. 22:06Javascript/Sencha

에러 발생

{
    text: '삭제',
    handler: function() {
        const grid = this.up('grid');
        const selection = grid.getSelectionModel().getSelection();

        Ext.Ajax.request({
            url: '/location/delete_image',
            params: {
                _csrf: document.getElementById('_csrf').innerText,
            },
            method: 'POST',
            jsonData: {
                data: selection
            },
            success: function(response) {
            },
            failure: function(response) {
            }
        });
    }
}

정상: selection에서 data를 뽑아내야 함

{
    text: '삭제',
    handler: function() {
        const grid = this.up('grid');
        const selection = grid.getSelectionModel().getSelection();

        // Extract raw data from the selection
        const data = selection.map(record => record.getData());

        Ext.Ajax.request({
            url: '/location/delete_image',
            params: {
                _csrf: document.getElementById('_csrf').innerText,
            },
            method: 'POST',
            jsonData: {
                data: data, // Send the extracted data
            },
            success: function(response) {
            },
            failure: function(response) {
            }
        });
    }
}

row가 한개일 경우

const selection = treeGrid.getSelectionModel().getSelection()[0];
const data = selection.get('id');