如何获取 ExtJS Combobox 的选定索引
确定 ExtJS 中组合框中当前所选项目索引的经过认证的方法是什么?
ExtJS 3.x 和 4 之间的执行方式有区别吗?
var combo = new Ext.form.ComboBox(config);
var selectedIndex = combo.selectedIndex; // TODO: Implement
if(selectedIndex > 2) {
// Do something
}
关于如何将其作为属性添加到 ComboBox 对象的奖励点。
What is the certified way to determine the index of the currently selected item in a ComboBox in ExtJS?
Is there a difference on how to do this between ExtJS 3.x and 4?
var combo = new Ext.form.ComboBox(config);
var selectedIndex = combo.selectedIndex; // TODO: Implement
if(selectedIndex > 2) {
// Do something
}
Bonus-points for how to add it as a property to the ComboBox-object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您有一个组合,其中 valueField 是组合商店使用的 id,您可以简单地避免搜索:
使用以下命令:
If you have a combo where valueField is the id used by the combo's store, you can simply avoid the search:
using this:
我想你必须使用组合商店才能做到这一点。 Combos 有一个私有的 findRecord 方法,可以按属性和值对存储进行简单的搜索。您可以在源代码本身中查看示例(Combo.js 第 1119 行)。
1)基于此,您可以通过这种方式找到选定的索引:
2)或者您可以将自己绑定到“select”事件,该事件是用组合、选定的记录及其索引作为参数触发的。
3)您还可以访问视图的 getSelectedIndexes() 但我怀疑这是一个好的解决方案(因为我不确定它始终可用)
最后,如果您想扩展组合框对象,我认为这应该可行(如果您去与第一个解决方案):
I think you'll have to use the combo's store for that. Combos have a private
findRecord
method that'll do a simple search over the store by property and value. You can see an example in the sourcecode itself (Combo.js line 1119).1) Based on this you could find the selected index this way :
2) Or you could bind yourself to the "select" event which is fired with the combo, the record selected and its index as a parameter.
3) You could also access the view's getSelectedIndexes() but I doubt it's a good solution (in that I'm not sure it's available all the time)
Finally if you want to extend the combobox object I think this should work (if you go with the first solution) :
在 Ext 4.0.2 中,相同的代码如下所示:
Jad,您的 return 语句中缺少右括号...只是认为您应该知道。
In Ext 4.0.2 the same code would look like:
Jad, you're missing a closing parenthesis on your return statement... just thought you should know.