Jawad Al Shaikh
Jawad Al Shaikh

Reputation: 2735

convert jquery inArray to extjs equivalent

does extjs contain method equivalent to inArray? i checked the API but found nothing!

here is the jquery snippet that need urgent conversion:

if ($.inArray(checkbox.inputValue, values) >= 0)

where values is array.

thanks,

Upvotes: 2

Views: 2781

Answers (4)

sbgoran
sbgoran

Reputation: 3541

ExtJS 4 has Array.contains method:

Ext.Array.contains(MyArray, MyString); // returns bool

Upvotes: 2

Sinoptik
Sinoptik

Reputation: 1

You need to use the Ext.Array.indexOf method:

Ext.Array.indexOf( Array array, Object item, [Number from] ) : Number

documentation

The resulting code would look like this:

if (Ext.Array.indexOf(checkbox.inputValue, values) >= 0)

Upvotes: 0

John Flatness
John Flatness

Reputation: 33769

Ext JS has Array.indexOf, which does exactly the same thing that the unfortunately-named jQuery.inArray does:

if(values.indexOf(yourValue) !== -1)

Upvotes: 5

Jacob Relkin
Jacob Relkin

Reputation: 163248

Ext.js does not appear to have this function. See http://docs.sencha.com/core/manual/

You can monkey patch this in if you like:

Ext.inArray = function(value, collection) {
    return collection.indexOf(value) !== -1;
};

Upvotes: 2

Related Questions