Extjs 4组合框默认值 [英] Extjs 4 combobox default value

查看:112
本文介绍了Extjs 4组合框默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将应用程序从ExtJs 3迁移到4版本。
我的formPanel中有几个组合框,之前我已经使用了hiddenName
和所有这些东西提交valueField而不是displayField。

I'm migrating my application from ExtJs 3 to 4 version. I have several comboboxes at my formPanel, and previously I've used hiddenName and all that stuff to submit valueField instead of displayField.

所有我的适应工作正常(值字段提交),但是我无法设置默认值组合框,它们在页面加载后显示为空。
以前,我只是在配置中指定了'value'参数。
有什么想法如何解决?

All my adaptation works fine (value field IS submitting), but I can't set the default values for comboboxes, they are shown as empty after page load. Previously, I did that just with specifying the 'value' parameter in config. Is there any ideas how to fix that?

我的代码 - 模型和商店:

My code - Model and Store:

Ext.define('idNamePair', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'id', type: 'string'},
        {name: 'name',  type: 'string'}
    ]
});

var dirValuesStore = new Ext.data.Store({
    model: 'idNamePair',
    proxy: {
        type: 'ajax',
        url: '../filtervalues.json',
        reader: {
            type: 'json',
            root: 'dir'
        }
    },
    autoLoad: true
});

组合配置:

{
    triggerAction: 'all',
    id: 'dir_id',
    fieldLabel: 'Direction',
    queryMode: 'local',
    editable: false,
    xtype: 'combo',
    store : dirValuesStore,
    displayField:'name',
    valueField:'id',
    value: 'all',
    width: 250,
    forceSelection:true
}


推荐答案

我有同样的问题,afaik与选择列表渲染有关,然后将项目添加到商店。我尝试了上面提到的回调方法,没有任何运气(猜测它必须是在选择列表而不是商店的回调)。

I had the same problem, afaik has to do with selectlist rendering before the items are added to the store. I tried the callback method mentioned above without any luck (guess it would have to be a callback on the selectlist rather than the store).

添加项目后添加了这一行到商店,它工作正常:

I added this line after adding items to the store and it works fine:

Ext.getCmp('selectList').setValue(store.getAt('0').get('id'));

这篇关于Extjs 4组合框默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆