javascript - 如何修复免费 jqgrid 中未定义的从一个 jqgrid 列拖动到另一列时无法读取属性 'cellIndex'

标签 javascript jquery jqgrid free-jqgrid

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

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

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

无法读取未定义第 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)

更新

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

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

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

最佳答案

在我看来,你必须稍微改变你的代码。您应该始终测试您是否调用 $.jgrid.getCellIndex DOM 为 <td>元素而不是它的其他一些子元素。 $.jgrid.getCellIndex典型用法的代码片段应如下所示:

var $td = $(e.target).closest("tr.jqgrow>td");
if ($td.length > 0) {
    var iCol = $.jgrid.getCellIndex($td);
    ...
}

关于javascript - 如何修复免费 jqgrid 中未定义的从一个 jqgrid 列拖动到另一列时无法读取属性 'cellIndex',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29994984/

相关文章:

javascript - 是否可以在浏览器上编辑工具提示的字体系列?

javascript - Javascript 毫秒问题

javascript - flexslider 方向箭头响应

javascript - Konva从点击事件中获取图像ID

javascript - 以下语法有什么问题: Its not working

jquery - 存储相关的行数据?

javascript - 使用 ScaleBand 从范围中获取域

javascript - 是否有保存函数的 javascript 变量的命名约定?

jQuery/css 目标第 n 个子类

javascript - 将数据复制到 JQGrid