2013-07-06 154 views
0

時不時地在我的手機應用程序,我得到這個錯誤,這個錯誤FACEBOOK「遺漏的類型錯誤:無法讀取未定義的屬性‘類型’」

Uncaught TypeError: Cannot read property 'type' of undefined

此錯誤是從以下行來;

if ((post.attachment.media !== undefined) && (post.attachment.media[0].type == "photo")) 

我只是有時會得到它,這取決於我認爲的新聞提要。有時它完美並且沒有錯誤。有任何想法嗎?

回答

0

該錯誤表明,即使定義了post.attachment.media,該錯誤仍然不是數組,而是一個空數組。你可以通過以下方式來保護:

if ((post.attachment.media !== undefined) && 
    (post.attachment.media.length > 0) && 
    (post.attachment.media[0].type == "photo")) 
+0

謝謝,我已經包括它,並且至今沒有再次出現錯誤!所以它的作品!謝謝 – Dot

相關問題