繁体   English   中英

组合框不从下拉列表中选择值

[英]Combo box do not select Value from drop down

我正在使用ExtJs来创建一个组合框。 这是我的代码:

Ext.define('Form.FormTypeDialog', {
extend : 'Ext.Window',

id: 'formTypeDialog',

formId: null,

callbackFunction : null,

modal: true,

statics : {
    show : function(formId, callback) {
        Ext.create(Form.FormTypeDialog", {
            formId : formId,
            callbackFunction : callback
        }).show();
    }
},

constructor : function(config) {
    var me = this;

    Ext.apply(this, {
        buttons : [
            {
                text:"#{msgs.form_create_dialog_button_cancel}",
                cls : 'secondaryBtn',
                handler: function() {
                    me.close();
                }
            },
            {
                text:"#{msgs.form_create_dialog_button_next}",
                handler: function() {
                    // Get selected form type

                }
            }
        ]
    });
    this.callParent(arguments);
},

initComponent:function() {
    this.setTitle("#{msgs.form_create_dialog_title}");
    this.setHeight(175);
    this.setWidth(327);

    var formTypeStore = Mystore.Store.createRestStore({
        url : getRelativeUrl('/rest/form/formTypes'),
        root: 'objects',
        fields: ['name','value']
    });

    this.form = new Ext.form.Panel({
        style:'padding:15px;background-color:#fff' ,
        border:false,
        bodyBorder:false,
        items:[
            new Ext.form.Label({
                text: "#{msgs.form_create_dialog_select_type_label}",
                margin: "25 10 25 5"
            }),
            new Ext.form.ComboBox({
                id: 'createformTypeCombo',
                margin: "8 10 25 5",
                allowBlank: false,
                forceSelection: true,
                editable:false,
                store: formTypeStore,
                valueField: 'value',
                displayField: 'name',
                width: 260,
                emptyText: '#{msgs.form_create_dialog_select_type}'
            })
        ]
    });

    this.items = [
        this.form
    ];

    this.callParent(arguments);
}
});    

我在按钮点击的xhtml页面上创建此窗口使用:

Form.FormTypeDialog.show(null, showFormWindowCallBack);

它工作正常,显示组合框,我可以选择值。

但是如果我打开并关闭它4次,那么在下一个节目中它会显示值,但它不允许我选择最后两个值。 我只能选择第一个值。

在此输入图像描述

请建议。

注意:我尝试以我的应用程序的其他页面的形式复制和执行此代码。 但在所有情况下行为都是一样的。 这个组合框位于Ext.Window上。

编辑:休息的JSON响应:

{“attributes”:null,“complete”:true,“count”:3,“errors”:null,“failure”:false,“metaData”:null,“objects”:[{“name”:“Application provisioning策略表单“,”值“:”应用程序“},{”名称“:”角色供应策略表单“,”值“:”角色“},{”名称“:”工作流表单“,”值“:”工作流程“}],” 请求ID “:空,” 重试 “:假的,” retryWait “:0,” 状态 “:” 成功”, “成功”:真正的 “警告”:空}

我重新创建了这段代码,我在Firefox中直接使用你的代码显示了一些错误,所以我改变了一些东西。

运行下面的代码并调用Ext.create("Form.FormTypeDialog", {}).show(); 在控制台窗口中,然后关闭窗口并重复不会复制此问题。 你能尝试使用我的代码,看看你是否还有同样的问题。

Ext.application({
    name: 'HelloExt',
    launch: function () {
        Ext.define('Form.FormTypeDialog', {
            extend: 'Ext.Window',
            id: 'formTypeDialog',
            formId: null,
            callbackFunction: null,
            modal: true,

            constructor: function (config) {
                var me = this;

                Ext.apply(this, {
                    buttons: [
                        {
                            text: "#{msgs.form_create_dialog_button_cancel}",
                            cls: 'secondaryBtn',
                            handler: function () {
                                me.close();
                            }
                        },
                        {
                            text: "#{msgs.form_create_dialog_button_next}",
                            handler: function () {
                                // Get selected form type

                            }
                        }
                    ]
                });
                this.callParent(arguments);
            },

            initComponent: function () {
                this.setTitle("#{msgs.form_create_dialog_title}");
                this.setHeight(175);
                this.setWidth(327);

                var myData = [
                    ["Application Provisioning Policy Form", "Application"],
                    ["Role Provisioning Policy Form", "Role"],
                    ["Workflow Form", "Workflow"],
                ];

                var formTypeStore = Ext.create("Ext.data.ArrayStore", {
                    fields: [
                        'name',
                        'value'
                    ],
                    data: myData,
                    storeId: "myStore"
                });

                this.form = Ext.create("Ext.form.Panel", {
                    style: 'padding:15px;background-color:#fff',
                    border: false,
                    bodyBorder: false,
                    items: [
                        Ext.create("Ext.form.Label", {
                            text: "#{msgs.form_create_dialog_select_type_label}",
                            margin: "25 10 25 5"
                        }),
                        Ext.create("Ext.form.ComboBox", {
                            id: 'createformTypeCombo',
                            margin: "8 10 25 5",
                            allowBlank: false,
                            forceSelection: true,
                            editable: false,
                            store: formTypeStore,
                            valueField: 'value',
                            displayField: 'name',
                            width: 260,
                            emptyText: '#{msgs.form_create_dialog_select_type}'
                        })
                    ]
                });

                this.items = [
                    this.form
                ];

                this.callParent(arguments);
            }
        });

        Ext.create('Ext.Button', {
            text: 'Click me',
            renderTo: Ext.getBody(),
            handler: function() {
                Ext.create("Form.FormTypeDialog", {}).show();
            }
        });
    }
});

您也可以使用此Fiddle中的 / forking来使用此代码

目前尚不清楚你的问题是什么。 我使用远程组合如下:

Ext.define('ComboRemote', {
extend: 'Ext.form.ComboBox',
xtype: 'ComboRemote',
emptyText: 'empty',
width: 75,
displayField: 'name',
valueField: 'id',
store: {
    model: 'ComboModel',
    proxy: {
        type: 'rest',
        url: '/serv/Res',
        extraParams: {
            query: ''
        },
        reader: {
            root: "result", type: 'json'
        }
    },
    autoLoad: true,
},
queryMode: 'remote',
pageSize: false,
lastQuery: '',
minChars: 0});

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

我希望能帮到你

尝试这些可能的解决方案1.将store的AutoLoad属性设置为true。 2.添加几毫秒的延迟

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM