我有一个简单的模型 -
Ext.define('MyModel', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.field.String'
],
fields: [
{
type: 'string',
name: 'currentA'
},
{
type: 'string',
name: 'currentB'
},
{
name: 'A'
},
{
name: 'B'
}
]
});
这是我正在对该模型的数据执行的一些操作-
onBeforeRender: function(component, eOpts) {
var mystore = Ext.getStore('Mystore');
mystore.load({
callback: function(){
var entity = headerStore.getAt(0);
var bs = entity.data.B;
var as = entity.data.A;
var currentB = entity.data.currentB;
var currentA = entity.data.currentA;
bs.forEach(function(record) {
// do some operations
});
as.forEach(function(record) {
// do some other operations
});
}
});
}
现在,当遍历显然是一个对象数组的变量“bs”时,IE 8 会报错
“对象不支持此属性或方法”
forEach 函数。这在 Chrome 中运行良好。
这是模型的 json -
{
"currentA": "a",
"currentB": "b",
"A": [
{
"name": "a",
"id": 1
}
],
"B": [
{
"name": "b",
"id": 2
}
]
}
为什么IE不能识别为数组?
最佳答案
您可以使用 .each
来自 Ext.Array
,因为 IE8 不支持 .forEach
Ext.Array.each(bs, function(record) {
});
Ext.Array.each(as, function(record) {
});
[].forEach
不依赖于 ExtJS 版本,因为这是在 ES5
标准中添加的 JS Array 方法。来自 this link
你可以看到哪个浏览器支持 forEach
方法。
关于javascript - ExtJs 5.0 : forEach on Array of Objects not working in IE8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28898344/