简体   繁体   中英

extjs4 Object doesn't support property or method 'indexOf' IE 8 workaround issue

My User defined sort function does not work in IE 8.

Object doesn't support property or method 'indexOf'

roles_store.sort([{
    sorterFn: function(v1, v2) {
    var order = ['read-only', 'user', 'admin', 'super'],
        v1o   = order.indexOf(v1.get('role_name')),
        v2o   = order.indexOf(v2.get('role_name'));           

        return v1o < v2o ? -1 : 1;; 
    }
}]);

The following link shows a workaround: How to fix Array indexOf() in JavaScript for Internet Explorer browsers

I tried replacing indexof with Array.prototype.indexOf

v2o = order.Array.prototype.indexOf (v2.get('role_name'));

I apologize if I missed something here

Use Ext.Array.indexOf, it defers to the native indexOf where possible.

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Array-method-indexOf

IE 8 is a little old and it includes an old javascript version. It doesn´t have a lot of very useful methods that we use everyday. I recommend to include the tiny Array prototype extensions library ( link ). That library allows you to use all the methods (for arrays) that all new browsers (with newer javascript version) include.

You also can use the Extjs methods as Evan suggests (they work well) but you have to have that in mind all the time and most of the snippets and code samples that you find in internet or this site won´t run (you will have to translate them to use extjs methods). Another problem is that your code will works ok in Chrome and FF but not in IE if you not take care.

It is much more easy and safe to include the extensions that I recommend you, that´s what we did in our own project and it was a great solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM