gpt4 book ai didi

extjs - 如何从 ExtJS 网格中双击的行中获取数据?

转载 作者:行者123 更新时间:2023-12-01 08:24:02 25 4
gpt4 key购买 nike

在 ExtJS 网格中,我可以像这样获取所选数据项的索引:

grid.getSelectionModel().on('rowselect', function(sm, index, rec){
changeMenuItemInfoArea(menuItemApplication, 'you are on row with index ' + index);
var row_number_parts = rec.id.split('-'); // rec.id = e.g. "ext-record-1"
var selected_index = row_number_parts[2] - 1;
alert(selected_index);
});

但是如何在双击时获取所选数据项的索引?

当我这样做时:

listeners: {
'rowdblclick': function(grid, rowindex, e){
console.log(...);
}
}

gride 似乎都没有我需要的信息,并且 rowindex 没有用,因为如果用户使用列,则双击行的索引不一定是加载网格的数据集的索引。

附录

感谢@McStretch,我最终解决了手头的问题,将id放入项目列表,隐藏id列,然后将id发送到编辑页面,如下所示:

listeners: {
'rowdblclick': function(grid, index, rec){
var id = grid.getSelectionModel().getSelected().json[0];
go_to_page('edit_item', 'id=' + id);
}
}

最佳答案

根据cellClick的文档,Index实际上是指存储中记录的索引:

function(grid, rowIndex, columnIndex, e) {
// Get the Record, this is the point at which rowIndex references a
// record's index in the grid's store.
var record = grid.getStore().getAt(rowIndex);

// Get field name
var fieldName = grid.getColumnModel().getDataIndex(columnIndex);
var data = record.get(fieldName);
}

如果是这种情况,那么您不必担心网格重新排序。我认为您应该通过在 'rowdblclick' 监听器中使用上述方法来获取索引/记录——它更具可读性。测试一下,看看会发生什么。

关于extjs - 如何从 ExtJS 网格中双击的行中获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4389410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com