gpt4 book ai didi

javascript - 如何获取 sap.m.table 中选定单元格的索引(行/列)?

转载 作者:行者123 更新时间:2023-11-30 14:03:50 25 4
gpt4 key购买 nike

我在获取表格中所选单元格的索引时遇到问题。我已经为每个单元格附加了一个点击功能,该功能应该在按下时提醒索引,但我无法正确获取索引。行的索引是正确的,但列的索引总是不正确。

function doSomething(i) {
setTimeout(function() {
for (var j = 0; j < columnNum; j++) {
oTable.getItems()[i].getCells()[j].$().parent().click(function() {
alert(i+", "+j);
});
}
}, i);
}

for (var i = 0; i < rowNum; i++) {
doSomething(i);
}

这是完整的 fiddle :https://jsbin.com/hecuhevawe/1/edit?html,css,js,output .

最佳答案

尝试更改最后一个循环,以便遍历所有单元格并将行和列索引传递给 doSomething 函数。

function doSomething(i,j) {
setTimeout(function() {
oTable.getItems()[i].getCells()[j].$().parent().click(function() {
alert(i+", "+j);
});
}, i);
}

for (var i = 0; i < rowNum; i++) {
for (var j = 0; j < columnNum; j++) {
doSomething(i,j);
}
}

关于javascript - 如何获取 sap.m.table 中选定单元格的索引(行/列)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55839417/

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