2011-03-11 57 views

回答

5

Ext JS的有Array.indexOf,这正是这么做的不幸命名jQuery.inArray做同样的事情:

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

请注意,这是特定于Ext 3的 - 在Ext 4中,Array原型不再进行修改,因此您应该使用Ext.Array.indexOf。 – 2012-01-06 17:03:28

2

Ext.js似乎没有此功能。见http://docs.sencha.com/core/manual/

,如果你喜欢,你可以猴子修补这个在:

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

为了澄清,分机*核心*没有它,但Ext JS的(在标准库)不支持它,如其他答案所示。此外,我相信jQuery.inArray,就像Array.indexOf,返回匹配的索引或-1,而不是像这个示例代码一样的布尔值(尽管名字肯定意味着它是一个布尔值,不幸的是)。 – 2012-01-06 17:08:54

0

您需要使用Ext.Array.indexOf方法:

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

documentation

生成的代码应该是这样的:

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