javascript - 对象 1011 没有方法 'startsWith'

标签 javascript angularjs ionic-framework

我正在尝试根据所选产品对我的产品详细信息对象进行分类。

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 中出现错误:

Object 1011 has no method 'startsWith'

1011 是我的产品代码。

有人知道为什么会发生这种情况吗?

最佳答案

在 Android 版本之间,JavaScript 引擎并不总是相同,并且最新功能并不总是可用。

我遇到了同样的问题:你必须在调用startsWith之前添加一个polyfill。

检查 Mozilla 页面上的 polyfill 部分:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith

关于javascript - 对象 1011 没有方法 'startsWith',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46682698/

相关文章:

javascript - 对话框在 iOS 7 全屏 Web 应用程序中不起作用

javascript - 根据可见区域设置div的高度

javascript - 在angularjs中获取模块名称及其所有依赖项列表

angular - 在 ionic 2 应用程序中使用 promise with observable

javascript - select2 文本框上的按键事件不起作用

javascript - 如何用 Knex.js 查询多对多关系?

javascript - Angular 2 : Populating components to template

javascript - 从两个表达式设置 ng-checked 值

javascript - 在 ionic 中使用 stateParam

javascript - 是否可以使用地理位置作为条件来发出通知?