ExtJS 4 - 组合框问题

发布于 2024-12-04 04:51:04 字数 2430 浏览 1 评论 0原文

我在使用 extjs 组合框时遇到问题(无论浏览器如何,在 Chrome 和 FF 中进行测试,结果相同)。

组合框加载得很好,两个条目都显示了。我可以选择最初加载的两个之一,但是如果我在选择后尝试更改选择,它将保留原始值,并且不会触发任何选择或更改事件。我发现,如果我开始输入未选定的条目,自动完成将接管,我可以按回车键来选择条目,然后会触发选择事件和更改事件。为什么我不能简单地单击未选择的条目来选择它?

这是模型、读取器、数据存储和组合框代码:

//Model
Ext.define('cbMonitorModel', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'iMonitorID', type: 'String'},
        {name: 'sMonitorName', type: 'String'}
    ]
});

//Reader
var cbMonitorReader = Ext.create('Ext.data.JsonReader',{
    type: 'json',
    model: 'cbMonitorModel'
});

//Store
var cbMonitorDataStore = Ext.create('Ext.data.Store',{
fields: ['iMonitorId','sMonitorName'],
autoLoad: true,
proxy: {
    type: 'ajax',
    url: '/inc/ajax/Monitors.php',
    actionMethods: 'POST',
    reader: cbMonitorReader,
    extraParams: {
        task: 'getMonitors',
        domain: sMonitorDomainName
    }
}
});

//ComboBox
Ext.create('Ext.form.ComboBox',{
    fieldLabel: 'Monitor',
    store: cbMonitorDataStore,
    queryMode: 'local',
    displayField: 'sMonitorName',
    valueField: 'iMonitorId',
    renderTo: Ext.get('monitorSelect'),
    width: 400,
    listeners: {
        select: function(combo, records, opts) {
            console.log('MonitorComboBox - Select');
            console.log(combo);
            console.log(records);
            console.log(opts);
            console.log(cbMonitorDataStore);
            console.log('--------------------------------------------------------------------');
        }
    }
});

代理返回以下字符串:

[{"iMonitorID":"85","sMonitorName":"6176 - xxx.xxx.xxx.xxx default monitor"},{"iMonitorID":"86","sMonitorName":"14177 - aaa.bbbbbbbbb.com default monitor"}]

谢谢。任何帮助将不胜感激。


编辑: 2011-09-08 16:32 CST

我仍然没有弄清楚这个问题,但与此同时,我找到了一个“肮脏”的解决方法......扩展事件清除了以前的值,这允许用户选择不同的值,但问题是我无法使用“getValue()”...因此 cb.lastSelection[0].raw.iMonitorID 字符串...

ComboBox 代码:

var MonitorCB = Ext.create('Ext.form.ComboBox', {
    fieldLabel: 'Monitor',
    store: cbMonitorDataStore,
    queryMode: 'local',
    displayField: 'sMonitorName',
    valueField: 'iMonitorName',
    width: 400,
    renderTo: 'monitorSelect',
    listeners: {
        select: function(cb, rec, opts){
            console.log(cb.lastSelection[0].raw.iMonitorID);
        },
        expand: function(){this.clearValue()}
    }
});

I've got an issue when using an extjs combo box (regardless of browser, tested in Chrome and FF with same result).

The combo box loads just fine, both entries are displayed. I can select one of the two that are loaded initially, but if I try and change the selection after I've already selected, it keeps the original value and no select or change event is fired. I found that if I start typing in the non-selected entry, auto complete takes over, and I can hit the return key to select the entry and a select event and change event are fired. Why can I not just simply click on the unselected entry to select it?

Here's the model, reader, data store, and combo box code:

//Model
Ext.define('cbMonitorModel', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'iMonitorID', type: 'String'},
        {name: 'sMonitorName', type: 'String'}
    ]
});

//Reader
var cbMonitorReader = Ext.create('Ext.data.JsonReader',{
    type: 'json',
    model: 'cbMonitorModel'
});

//Store
var cbMonitorDataStore = Ext.create('Ext.data.Store',{
fields: ['iMonitorId','sMonitorName'],
autoLoad: true,
proxy: {
    type: 'ajax',
    url: '/inc/ajax/Monitors.php',
    actionMethods: 'POST',
    reader: cbMonitorReader,
    extraParams: {
        task: 'getMonitors',
        domain: sMonitorDomainName
    }
}
});

//ComboBox
Ext.create('Ext.form.ComboBox',{
    fieldLabel: 'Monitor',
    store: cbMonitorDataStore,
    queryMode: 'local',
    displayField: 'sMonitorName',
    valueField: 'iMonitorId',
    renderTo: Ext.get('monitorSelect'),
    width: 400,
    listeners: {
        select: function(combo, records, opts) {
            console.log('MonitorComboBox - Select');
            console.log(combo);
            console.log(records);
            console.log(opts);
            console.log(cbMonitorDataStore);
            console.log('--------------------------------------------------------------------');
        }
    }
});

The proxy returns the following string:

[{"iMonitorID":"85","sMonitorName":"6176 - xxx.xxx.xxx.xxx default monitor"},{"iMonitorID":"86","sMonitorName":"14177 - aaa.bbbbbbbbb.com default monitor"}]

Thanks. Any help would be appreciated.


Edit: 2011-09-08 16:32 CST

I still haven't figured this problem out, but in the meantime, I've found a "dirty" work around... expand event clears out the previous value, which allows the user to select a different value, but then the problem was that I couldn't use "getValue()"... hence the cb.lastSelection[0].raw.iMonitorID string...

ComboBox code:

var MonitorCB = Ext.create('Ext.form.ComboBox', {
    fieldLabel: 'Monitor',
    store: cbMonitorDataStore,
    queryMode: 'local',
    displayField: 'sMonitorName',
    valueField: 'iMonitorName',
    width: 400,
    renderTo: 'monitorSelect',
    listeners: {
        select: function(cb, rec, opts){
            console.log(cb.lastSelection[0].raw.iMonitorID);
        },
        expand: function(){this.clearValue()}
    }
});

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

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

发布评论

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

评论(1

∞梦里开花 2024-12-11 04:51:04

你的代码有错误。在组合框配置中 valueField: 'iMonitorId' 用小写字母 d 指定,而在模型配置中 name: 'iMonitorID' 用大写字母指定 (并且代理返回'iMonitorID'

顺便一提。您正在使用具有模型和商店字段配置的阅读器。未使用正确模型的字段配置,因为商店已经具有错误的字段配置。

因此解决方案是:

1.删除商店配置中的字段:['iMonitorId','sMonitorName'],
2. 将组合框配置中的 valueField 更改为 'iMonitorID'

You have mistake in your code. In combobox config valueField: 'iMonitorId' is specified with small letter d whereas in model config name: 'iMonitorID' is specified with large one (and the proxy returns 'iMonitorID's).

By the way. You are using both reader with model and store's fields config. The correct model's fields config is not used because store already have the wrong fields config.

So the solution would be:

1. get rid of fields: ['iMonitorId','sMonitorName'], in store's config.
2. change valueField to 'iMonitorID' in combobox' config.

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