gpt4 book ai didi

javascript 和 extJs - 范围问题

转载 作者:行者123 更新时间:2023-11-28 10:32:50 24 4
gpt4 key购买 nike

我在一些 js 代码中遇到了一些与范围相关的问题,也许有人可以向我解释我做错了什么:

我正在使用 extJs 并得到了这个片段:

Ext.onReady(function(){

// Form for filter selection
var formFilter = new Ext.FormPanel({
// ...
items: [
cbGroup = new Ext.form.ComboBox({
fieldLabel: 'Group',
store: dsGroups,
displayField: 'name',
valueField: 'number',
emptyText : '- Please choose a group -',
listeners:{
'select': function() {
alert(cbGroup.selectedIndex +' '+this.selectedIndex);
}
}
})
]
});
});

问题:当我在监听器函数中通过“this”访问组合框时,我得到了 selectIndex 属性的正确结果。当我通过其变量名称访问组合框时,我总是得到结果“-1”。非常感谢您的帮助!

最佳答案

快速而肮脏:

Ext.onReady(function(){
var self = this;
...
alert(cbGroup.selectedIndex +' '+self.selectedIndex);

关于javascript 和 extJs - 范围问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2584592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com