IE 11 AngularJS错误-对象不支持属性或方法“来自" [英] IE 11 AngularJS error - Object doesn't support property or method 'from'

查看:99
本文介绍了IE 11 AngularJS错误-对象不支持属性或方法“来自"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的JavaScript中,我有一个函数detectEnvironmentAndGetLEAndDepot(),该函数通过HTML称为onload.我正在使用wicket,需要获取后端保存的值,因此将它们发射到屏幕上,将其隐藏,然后从我的JS中搜索<span>值以获取name值,例如if(v.getAttribute('name') === 'LE'){do stuff}if(v.getAttribute('name') === 'depot'){do stuff}(我确定这不是最优雅的解决方案,但我需要一个快速的解决方案!).然后在函数detectEnvironmentAndGetLEAndDepot()中,我进行了一些格式化等操作,以便使数据可用.

In my JavaScript I have a function detectEnvironmentAndGetLEAndDepot() which is called onload via HTML. I'm working with wicket, and need to take values held in the back-end, so I fire them to the screen, hide them, and search the <span> values from my JS for the name value, for example if(v.getAttribute('name') === 'LE'){do stuff} or if(v.getAttribute('name') === 'depot'){do stuff} (I'm sure not the most elegant solution, but I needed a quick one!). Then within the function detectEnvironmentAndGetLEAndDepot() I do a bit of formatting etc so the data is usable.

detectEnvironmentAndGetLEAndDepot()函数(很长,只有相关部分)-

detectEnvironmentAndGetLEAndDepot() function (quite long, only relevant part) -

detectEnvironmentAndGetLEAndDepot = function() {

    Array.from(document.getElementsByTagName('span')).forEach(function(v) {

//Search name tag for particular names, then do formatting
}

当我在IE11中打开此文件时,我在弹出式窗口SCRIPT438: Object doesn't support property or method 'from'中收到错误,该消息与上述方法的第一行-Array类有关.非常感谢.

When I open this in IE11 I get the error in a popup SCRIPT438: Object doesn't support property or method 'from' which is related to the first line of the method above - the Array class. Help much appreciated.

推荐答案

由于IE不支持Array.from方法,因此您可以尝试使用:

As Array.from method is not supported by IE, you can try to use:

[].slice.call(document.getElementsByTagName('span')).forEach(function(v) {});

这不需要使用任何第三方库.

This doesn't require usage of any 3rd party libraries.

这篇关于IE 11 AngularJS错误-对象不支持属性或方法“来自"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆