清除 ExtJS 组合框输入字段

发布于 2024-10-12 03:55:01 字数 480 浏览 4 评论 0原文

我有一个具有以下属性的 Ext.form.ComboBox:

fieldLabel: 'Regiune',
valueField: 'id',
displayField: 'reg',
id: 'cbRegR',
typeAhead: true,
store: new Ext.data.JsonStore({...}),
mode: 'local',
emptyText: '',
listeners:{...}

问题是,在从下拉列表中选择一个值以查看所有列表项后,我必须手动删除组合框的输入字段。问题是列表仅显示输入字段中以字母开头的项目。

如何清除扩展下拉列表中的输入字段?我尝试了以下方法,但不起作用:

listeners: { 'expand': function() { cbRegR.clearValue(); } }

似乎很容易,但对我来说并非如此..有什么好主意吗?提前致谢。

I have an Ext.form.ComboBox with the following properties:

fieldLabel: 'Regiune',
valueField: 'id',
displayField: 'reg',
id: 'cbRegR',
typeAhead: true,
store: new Ext.data.JsonStore({...}),
mode: 'local',
emptyText: '',
listeners:{...}

The problem is that I have to manually delete the combobox' input field after selecting a value from the dropdown list to view all the list items. The matter is the list displays only the items that begin with letters in input field.

How can I clear the input field on expanding dropdown list? I tried the following but it doesn't work:

listeners: { 'expand': function() { cbRegR.clearValue(); } }

Seems to be easy but it ain't so for me.. Any bright ideas? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

淡墨 2024-10-19 03:55:01

将配置属性添加到组合框

triggerAction: 'all'

可能会解决问题,而无需注册展开事件处理程序或清除组合框的值

Adding the config property to your combobox

triggerAction: 'all'

might do the trick, without the need to register an expand event handler or clearing the combobox's value

燕归巢 2024-10-19 03:55:01

正如您所知,根据字段值过滤列表项是 Ext JS ComboBox-es 的固有行为。

您可以明显地重写 Expand() 方法,在呈现列表之前进行添加以清除该值。例如:

Ext.override(Ext.form.ComboBox, {

    expand : function(){
        if(this.isExpanded() || !this.hasFocus){
            return;
        }
        //ADDITIONS HERE:
        this.clearValue();
        this.doQuery("", true);
        //ADDITIONS END HERE

        if(this.title || this.pageSize){
            this.assetHeight = 0;
            if(this.title){
                this.assetHeight += this.header.getHeight();
            }
            if(this.pageSize){
                this.assetHeight += this.footer.getHeight();
            }
        }

        if(this.bufferSize){
            this.doResize(this.bufferSize);
            delete this.bufferSize;
        }
        this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));

        // zindex can change, re-check it and set it if necessary
        this.list.setZIndex(this.getZIndex());
        this.list.show();
        if(Ext.isGecko2){
            this.innerList.setOverflow('auto'); // necessary for FF 2.0/Mac
        }
        this.mon(Ext.getDoc(), {
            scope: this,
            mousewheel: this.collapseIf,
            mousedown: this.collapseIf
        });
        this.fireEvent('expand', this);
    }

});

It is an intrinsic behaviour of Ext JS ComboBox-es to filter the list items based on the field value, as you already know.

You could perceivably override the expand() method, making additions to clear out the value before it renders the list. EG:

Ext.override(Ext.form.ComboBox, {

    expand : function(){
        if(this.isExpanded() || !this.hasFocus){
            return;
        }
        //ADDITIONS HERE:
        this.clearValue();
        this.doQuery("", true);
        //ADDITIONS END HERE

        if(this.title || this.pageSize){
            this.assetHeight = 0;
            if(this.title){
                this.assetHeight += this.header.getHeight();
            }
            if(this.pageSize){
                this.assetHeight += this.footer.getHeight();
            }
        }

        if(this.bufferSize){
            this.doResize(this.bufferSize);
            delete this.bufferSize;
        }
        this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));

        // zindex can change, re-check it and set it if necessary
        this.list.setZIndex(this.getZIndex());
        this.list.show();
        if(Ext.isGecko2){
            this.innerList.setOverflow('auto'); // necessary for FF 2.0/Mac
        }
        this.mon(Ext.getDoc(), {
            scope: this,
            mousewheel: this.collapseIf,
            mousedown: this.collapseIf
        });
        this.fireEvent('expand', this);
    }

});
撞了怀 2024-10-19 03:55:01

扩展事件是个好事件,但您必须小心其范围。

listeners: {
 'expand': function() {
    cbRegR.clearValue(); 
 },
 scope:this
}

设置范围有帮助吗?

The expand event is the good one but you have to be careful about the scope.

listeners: {
 'expand': function() {
    cbRegR.clearValue(); 
 },
 scope:this
}

Does setting the scope helps?

无需解释 2024-10-19 03:55:01

使用 cbRegR 不起作用,因为它是一个未定义的变量。使用

listeners: { 'expand': function() { Ext.getCmp('cbRegR').clearValue(); } }

或者,更复杂的方法:

listeners: { 'expand': function(self) { self.clearValue(); } }

Using cbRegR won't work, because it's an undefined variable. Either use

listeners: { 'expand': function() { Ext.getCmp('cbRegR').clearValue(); } }

or, a more sophisticated approach:

listeners: { 'expand': function(self) { self.clearValue(); } }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文