[英]JavaScript error in IE8 but not in IE 10
I am using IE 10 and developed a tree panel using ExtJs 4.1. 我正在使用IE 10,并使用ExtJs 4.1开发了一个树形面板。 When I run the application in IE 10 everything works fine but as soon as I switch to IE 8 (within IE 10 using IE developer toolbar browser mode option), I get JavaScript error.
当我在IE 10中运行该应用程序时,一切正常,但是一旦切换到IE 8(在IE 10中使用IE开发人员工具栏浏览器模式选项),我就会收到JavaScript错误。 I have never seen such inconsistent behavior so far with EXTJs.
到目前为止,我从未见过EXTJ出现这种不一致的行为。
Please using following fiddle to reproduce the issue. 请使用以下小提琴来重现该问题。
http://jsfiddle.net/BYqRN/20/ 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;
}
}
}
}
});
I am also attaching error which I am getting in IE 8 我还附加了我在IE 8中遇到的错误
Please provide your suggestion. 请提供您的建议。
Thank you 谢谢
reduce
isn't supported in old browsers, it's implemented in ECMA Script 5 check https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce 旧版浏览器不支持
reduce
,它是在ECMA Script 5中实现的。请检查https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce
you can define the function for the old browsers : 您可以为旧的浏览器定义功能:
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;
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.