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

查看:136
本文介绍了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.

我的所有适配都很好(值域提交),但我不能设置组合框的默认值,在页面加载后为空。
以前,我只是在config中指定了'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必须做的选择列表渲染之前的项目添加到商店。我试过上面提到的回调方法,没有任何运气(猜测它必须是selectlist而不是商店的回调)。

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天全站免登陆