4

データが存在しないときにデータ テーブルでマウスオーバー機能を実行すると、「未定義のプロパティ 'ntr' を読み取れません」というエラーが表示されます。テーブルにデータが入力されている場合は正常に機能します。コードは次のとおりです。

$('#example_table tbody td').live('mouseover mouseout', function(event) { 
if (event.type == 'mouseover') {// do something on mouseover 
    console.log('inside mouseover');
    var iPos = oTable.fnGetPosition( this ); // getting error in this line
    if(iPos!=null){
        console.log(iPos);
        var iCol= iPos [1];
    }
}
});

このエラーが発生しないようにするには、どのようなチェックを行う必要がありますか

ありがとう

4

1 に答える 1

1

テーブルにデータが入力されているかどうかを確認し、そうでない場合は次を返すことができます。

$('#example_table tbody td').live('mouseover mouseout', function(event) {
  if (event.type == 'mouseover') {// do something on mouseover 
    console.log('inside mouseover');

    // check if you have data in your table
    if (oTable.fnGetData().length <= 0) { // or some similar check
      return;
    }

    var iPos = oTable.fnGetPosition( this ); // getting error in this line
    if(iPos!=null){
      console.log(iPos);
      var iCol= iPos [1];
    }
  }
});
于 2013-08-16T09:04:26.303 に答える