2

我正在使用 IE 10 并使用 ExtJs 4.1 开发了一个树面板。当我在 IE 10 中运行应用程序时,一切正常,但是一旦我切换到 IE 8(在 IE 10 中使用 IE 开发人员工具栏浏览器模式选项),我就会收到 JavaScript 错误。到目前为止,我从未见过 EXTJ 出现这种不一致的行为。

请使用以下小提琴重现该问题。

http://jsfiddle.net/BYqRN/20/

Ext.create('Ext.tree.Panel', {
    title: 'Simple Tree',
    renderTo: Ext.getBody(),
    width: 400,
    height: 400,
    store: {
        root: {
            expanded: true,
            children: [{
                checked: false,
                text: "1 detention",
                expanded: true,
                children: [{
                    checked: false,
                    text: '1.1 foo',
                    leaf: false,
                    children: [{
                        checked: false,
                        text: "1.1.1 India",
                        expanded: true
                    }, {
                        checked: false,
                        text: "1.1.2 Singapore",
                        expanded: true
                    }, {
                        checked: false,
                        text: "1.1.3 USA",
                        expanded: true
                    }]
                }, {
                    checked: false,
                    text: '1.2 bar',
                    leaf: true
                }]
            }, {
                checked: false,
                text: "2 homework",
                expanded: true,
                children: [{
                    checked: false,
                    text: "2.1 book report",
                    leaf: true
                }, {
                    checked: false,
                    text: "2.2 algebra",
                    expanded: true,
                    children: [{
                        checked: false,
                        text: "2.2.1 buy lottery tickets",
                        leaf: true
                    }, {
                        checked: false,
                        text: "2.2.2 buy lottery tickets 2",
                        leaf: true
                    }]
                }, {
                    checked: false,
                    text: "2.3 English report",
                    leaf: true
                }]
            }, {
                checked: false,
                text: "3 buy lottery tickets",
                leaf: true
            }]
        }
    },
    rootVisible: false,
    disableSelection: true,
    //selModel: {mode: 'SIMPLE'},
    listeners: {
        checkchange: function (record, checked, opts) {
            if (!checked) return;
            var parentNode = record.parentNode;

            // Deselect children
            function deselectChildren(record) {
                record.eachChild(function (record) {
                    record.set('checked', false);
                    deselectChildren(record);
                });
            }
            deselectChildren(record);

            // See if all siblings are selected now
            var allSiblingSelected = false;
            if (parentNode) {
                allSiblingSelected = parentNode.childNodes.reduce(function (previous, node) {
                    return previous && node.get('checked');
                }, true);
            }

            if (allSiblingSelected) {
                parentNode.set('checked', true);
                // Apparently won't fire on its own
                this.fireEvent('checkchange', parentNode, true, opts);
            }

            // Deselect ancestors
            else {
                while (parentNode) {
                    parentNode.set('checked', false);
                    parentNode = parentNode.parentNode;
                }
            }
        }
    }
});

我还附加了我在 IE 8 中遇到的错误 在此处输入图像描述

请提供您的建议。

谢谢

4

1 回答 1

4

reduce旧浏览器不支持,它在 ECMA Script 5 中实现检查https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce

您可以为旧浏览器定义功能:

if ('function' !== typeof Array.prototype.reduce) {
  Array.prototype.reduce = function(callback, opt_initialValue){
    'use strict';
    if (null === this || 'undefined' === typeof this) {
      // At the moment all modern browsers, that support strict mode, have
      // native implementation of Array.prototype.reduce. For instance, IE8
      // does not support strict mode, so this check is actually useless.
      throw new TypeError(
          'Array.prototype.reduce called on null or undefined');
    }
    if ('function' !== typeof callback) {
      throw new TypeError(callback + ' is not a function');
    }
    var index = 0, length = this.length >>> 0, value, isValueSet = false;
    if (1 < arguments.length) {
      value = opt_initialValue;
      isValueSet = true;
    }
    for ( ; length > index; ++index) {
      if (!this.hasOwnProperty(index)) continue;
      if (isValueSet) {
        value = callback(value, this[index], index, this);
      } else {
        value = this[index];
        isValueSet = true;
      }
    }
    if (!isValueSet) {
      throw new TypeError('Reduce of empty array with no initial value');
    }
    return value;
  };
}
于 2013-08-07T11:22:57.897 回答