2015-09-15 30 views
0

當我運行我的控制器文件時,出現此錯誤。TypeError:無法讀取未定義的屬性'indexOf'

**TypeError: Cannot read property 'indexOf' of undefined** 

if (attribute.attributeId == 'created_on_attr' || attribute.attributeId == 'modified_on_attr' || 
     attribute.attributeId == 'created_by_attr' || attribute.attributeId == 'modified_by_attr'){ 
      alert(attribute.attributeId.indexOf("fileUpload")!= -1); 
      attribute.isEnabled = false; 
} 

你能提供這個

+2

你能提供此代碼嗎? – Matt

+0

提醒你的'屬性'JSON。你會發現attribute.attributeId未定義。 –

+0

使用===而不是==,應該解決問題 – harishr

回答

0

解決方案從您發佈的東西,看來該財產「屬性Id」不是「屬性」定義。您應該查看屬性變量並確保它具有您期望的所有屬性。

如果,另一方面,屬性ID是一個可選屬性,和你想測試是否都存在,如果它包含「文件上傳」,那麼你可能想是這樣的:

attribute.attributeId && attribute.attributeId.indexOf("fileUpload")!= -1

編輯在我發佈之後,您更新了您的問題,但我所說的一般要點仍然適用:您的if語句中沒有任何條件檢查您的對象上是否存在attributeId字段。所以,你的變量設置不正確,或者你只需​​要添加更多的關守代碼。

相關問題