将事件日志中的更新推送到IE8中不起作用的网页 [英] Pushing updates from event log to webpage not working in IE8

查看:277
本文介绍了将事件日志中的更新推送到IE8中不起作用的网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的MVC4应用程序中,我有一些代码将事件日志中的新条目推送到带有SignalR的网页。此代码适用于FireFox,但在IE8中,当新事件添加到事件日志时,调试器弹出错误:对象不支持此属性或方法并停止在以下代码中:

In my MVC4 application I have some code to push a new entry in the eventlog to a webpage with SignalR. This code works in FireFox, but in IE8 when a new event is added to the event log the debugger pops up with Error: Object doesn't support this property or method and stops at the following code:

this.notifyListeners = function (queryName, evt) {
        registeredListeners.forEach(function (item) {
            if (item.queryName === queryName) {
                item.listener.newEvent(evt);
            }
        });
    };

当我跳过此方法时,调试器关闭,事件显示在页面上。为什么会发生这种情况?如何解决这个问题?

When I step over this method the debugger closes and the event is shown on the page. Why does this happen and how can I workaround this?

推荐答案

forEach 在IE8中不支持你需要填充

forEach is not supported in IE8 you need to polyfill

像这里建议的那样:

https://developer.mozilla.org/en-US/docs/Web/ JavaScript / Reference / Global_Objects / Array / forEach

if (!Array.prototype.forEach)
{
  Array.prototype.forEach = function(fun /*, thisArg */)
  {
    "use strict";

    if (this === void 0 || this === null)
      throw new TypeError();

    var t = Object(this);
    var len = t.length >>> 0;
    if (typeof fun !== "function")
      throw new TypeError();

    var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
    for (var i = 0; i < len; i++)
    {
      if (i in t)
        fun.call(thisArg, t[i], i, t);
    }
  };
}

或者 c>循环,类似于:

Or perform and standard for loop, something like:

this.notifyListeners = function (queryName, evt) {
  var item={};
  for (i=0;i<registeredListeners.length;i++){
    item = registeredListeners[i];
            if (item.queryName === queryName) {
                item.listener.newEvent(evt);
            }
  }
};

这篇关于将事件日志中的更新推送到IE8中不起作用的网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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