2017-10-11 78 views
3

我想根據選定的產品對我的產品詳細信息對象進行分類。對象1011沒有方法'startsWith'

if (prodCode.startsWith("1") || prodCode.startsWith("4")) { 
    ProductDetails = obj.MachineDetails; 
} 
else if (prodCode.startsWith("6")) { 
    if (prodCode.charAt(3) == '3' || prodCode.charAt(3) == '4') { 
     ProductDetails = obj.BoxDetails; 
    } 
    else { 
     ProductDetails = obj.SomeDetails; 
    } 
} 
else if (prodCode.startsWith("2") || prodCode.startsWith("3")) { 
    ProductDetails = obj.SomeOtherDetails; 
} 

它的正常工作上面的是Android 4.4,但給出了Android 4.4的錯誤:

對象1011有沒有方法 'startsWith'

1011是我的產品代碼。

有沒有人有任何想法爲什麼發生?

+0

你能分享'console.log(String.prototype.startsWith);'和'console.log(typeof prodCode);''的輸出嗎? – gurvinder372

+1

嘗試開始使用Polyfill https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith#Polyfill – Satpal

回答