我正在使用IE 10并使用ExtJs 4.1开发了一个树状面板。当我在IE 10中运行应用程序时,一切正常,但只要我切换到IE 8(使用IE开发人员工具栏浏览器模式选项在IE 10中),我就会收到JavaScript错误。到目前为止,我从未见过使用EXTJs的这种不一致的行为。
请使用以下小提琴重现此问题。
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中收到的错误
请提供您的建议。
谢谢
答案 0 :(得分: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;
};
}