2

I've a simple model -

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'
        }
    ]
});

Here is some operation that I'm doing on the data for that model-

 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
            });
        }
    });
}

Now, when iterating over variable "bs", which is clearly an array of objects, IE 8 complains

"Object doesn't support this property or method"

for the forEach function. This works fine in Chrome.

Here is the json for the model -

{
  "currentA": "a",
  "currentB": "b",
  "A": [
    {
      "name": "a",
      "id": 1
    }
  ],
  "B": [
    {
      "name": "b",
      "id": 2
    }
  ]
}

Why is IE not able identify it as an array?

1
  • Mystore is the store for the Model Commented Mar 6, 2015 at 12:03

2 Answers 2

5

You can use .each from Ext.Array, because IE8 does not support .forEach

Ext.Array.each(bs, function(record) {
});

Ext.Array.each(as, function(record) {
});

[].forEach does not depend on ExtJS version because this is JS Array's method which was added in ES5 standard. From this link you can see which browser supports forEach method.

Sign up to request clarification or add additional context in comments.

Comments

1

Because IE8 doesn't implement forEach on arrays.

Use Ext.Array.forEach.

3 Comments

the same code has been working in IE 8 with extjs 4.2
You may have been including some other library.
I don't see any external library involved. Anyways it's not a problem at the moment. Was just curious.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.