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

问题描述

我正在将我的应用程序从 ExtJs 3 迁移到 4 版本.我的 formPanel 中有几个组合框,之前我使用了 hiddenName以及所有 stuff 提交 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 hiddenNameand all that stuff to submit valueField instead of displayField.

我的所有改编工作正常(值字段正在提交),但我无法设置组合框的默认值,它们在页面加载后显示为空.以前,我只是通过在 config.properties 中指定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 组合框默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 07:42