2016-08-22 7 views
0

nullが存在するかどうかをチェックしていてもJSがこのエラーをスローしています。たぶんあなたの人のうちの1人がこの1つで私を助けることができました。Uncaught TypeError:配列を使用してnullのプロパティ 'data'を読み取ることができません

if (typeof(this.callbacks['changed']) !== 'undefined') { 
     if (typeof(obj['item']['data']) !== 'undefined' && 
      (typeof(obj['item']['data'] != null))) { 
      this.callbacks['changed'](row, obj['item']['data']); 
     } 
    } 

このエラー:

Uncaught TypeError: Cannot read property 'data' of null

はすでにここから:&& (typeof(obj['item']['data'] != null)

+0

オブジェクトとは何ですか?コンソールログ – mplungjan

+1

'obj ['item']'は存在しないか、 'null 'です。 – Teemu

+1

これをすべて簡略化することができます。if(this.callbacks && this.callbacks.changed && obj && obj.item && obj.item.data){...} ' – Titus

答えて

0
if (typeof(this.callbacks['changed']) !== 'undefined') { 
     if (obj && obj.item && typeof(obj['item']['data']) !== 'undefined' && (typeof(obj['item']['data'] != null))) { 
      this.callbacks['changed'](row, obj['item']['data']); 
     } 
    } 
+0

ありがとうございます –

関連する問題