0

免费 jqgrid 将 beforeSelectRow 事件处理程序定义为

        beforeSelectRow: function (rowid, e) {
            var 
               colName = $.jgrid.getCellIndex($(e.target).closest('td')[0]),
               .... 

如果在一个 jqgrid 列中按住鼠标按钮,则鼠标光标移动到同一行的另一列并释放鼠标按钮,异常

无法读取未定义第 566 行的属性“cellIndex”

发生在第 808 行

               colName = $.jgrid.getCellIndex($(e.target).closest('td')[0]),

下面是堆栈跟踪(来自今天的 jquery.jqgrid.src.js 的行号)

如果鼠标光标移动到另一行按住按钮,则不会发生此异常。

如何解决或诊断此问题?$(e.target).closest('td')[0] 在同一行的列之间拖动时,它看起来是未定义的。

    Uncaught TypeError: Cannot read property 'cellIndex' of undefined Line 566 Column 12TypeError: Cannot read property 'cellIndex' of undefined  
  at Object.$.extend.getCellIndex (http://localhost:52216/admin/Scripts/jqgrid-4.8.0/js/jquery.jqgrid.src.js:566:12)  
  at HTMLTableElement.$grid.jqGrid.beforeSelectRow (http://localhost:52216/admin/Grid/Index/DoklstlG?_user=admin&_company=1:808:38)    
  at HTMLTableElement.$.extend.fullBoolFeedback (http://localhost:52216/admin/Scripts/jqgrid-4.8.0/js/jquery.jqgrid.src.js:1508:35)  
  at HTMLTableElement.$.extend.feedback (http://localhost:52216/admin/Scripts/jqgrid-4.8.0/js/jquery.jqgrid.src.js:1533:34)  
  at HTMLTableElement.feedback (http://localhost:52216/admin/Scripts/jqgrid-4.8.0/js/jquery.jqgrid.src.js:1618:26)  
  at HTMLTableElement.<anonymous> (http://localhost:52216/admin/Scripts/jqgrid-4.8.0/js/jquery.jqgrid.src.js:4283:55)  
  at HTMLTableElement.jQuery.event.dispatch (http://localhost:52216/admin/Scripts/jquery-1.11.2.js:4665:9) 
   at HTMLTableElement.elemData.handle (http://localhost:52216/admin/Scripts/jquery-1.11.2.js:4333:46)

更新

添加有问题的行后,剃刀解析器会引发语法错误。我尝试使用它,但仍然出现错误。

我通过使用解决了这个问题

        beforeSelectRow: function (rowid, e) {
            var iCol, td=$(e.target).closest('td')[0];
            if ( td  == undefined ) {
                return true;
            }
            iCol = $.jgrid.getCellIndex(td);
4

1 回答 1

1

It seems to me that you have to change your code a little. You should always test that you call $.jgrid.getCellIndex with DOM of <td> element and not with some other children of it. The code fragment of typical usage of $.jgrid.getCellIndex should be the following:

var $td = $(e.target).closest("tr.jqgrow>td");
if ($td.length > 0) {
    var iCol = $.jgrid.getCellIndex($td);
    ...
}
于 2015-05-01T21:00:14.347 回答