如何获取 sap.m.table 中所选单元格的索引 (row/column)?

How to get index (row/column) of selected cell in sap.m.table?

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

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);
    }
}