2013-07-06 92 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

相关问题