Javascript function fails to return element

我的未来我决定 提交于 2019-11-26 23:12:43

You are using .each() with a function

.each(function(){
    ...
    return this;
});
return false;

This will return from the callback (and maybe stop the each-loop if this was false), but never break out and return from the outer getCurrentCell function! So, that one will always return false.

Quick fix:

var result = false;
<...>.each(function(){
    if (<condition>) {
        result = <found element>;
        return false; // break each-loop
    }
});
return result; // still false if nothing found

Currently there is a better way to get currently selected in Handsontable. Just use the following methods from Handsontable:

handsontable('getSelected') - Returns index of the currently selected cells as an array [topLeftRow, topLeftCol, bottomRightRow, bottomRightCol]

handsontable('getCell', row, col) - Return element for given row,col

All methods are described here: https://github.com/warpech/jquery-handsontable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!