在ExtJS 3.0

时间:2016-02-24 10:41:47

标签: extjs combobox extjs3

我正在尝试在for循环内的表单上创建一个comboBox,但我无法这样做,有人可以帮忙吗?

我在stackoverflow上找到了这个代码但是这似乎不适用于我的EXTJS版本3.3

stackoverflow code:
for (var i=0; i < 8; i++) {
Ext.create('Ext.form.ComboBox', {
    fieldLabel: 'Combobox '+i,
    store: ['Option1','Option2'], //better to use a dynamic store
    renderTo: Ext.getBody()
});
};

我的代码:

var questionStore2 = null;

example.SurveyFieldDefaultWindow = Ext.extend(Ext.Window, {

    id: 'survey-field-win',
    title: 'Custom Survvey',
    modal: true,
    closable: true,
    width: 500,
    height: 600,
    frame: true,
    bodyStyle: 'padding: 5px',
    forceFit: true,
    constrainHeader: true,
    layout: 'fit',
    initComponent: function() {
        this.canEdit = this.checkEditPermissions();
        questionStore2 = questionStore;

        var data = questionStore2.data.items



        for (var i = 0; i < data.length; i++) {
            Ext.apply(
                this, {
                    items: [{
                        xtype: 'tabpanel',
                        id: 'survey-field-form-tabpanel',
                        layoutOnTabChange: true,
                        activeTab: 0,
                        items: [{
                            title: 'Questions',
                            layout: 'fit',

                            items: [{
                                xtype: 'form',
                                id: 'survey-field-form',
                                border: false,
                                bodyStyle: 'padding: 5px;',
                                frame: true,
                                defaultType: 'textfield',
                                items: [{
                                    xtype: 'combo',
                                    fieldLabel: data[i].data.name,
                                    hiddenName: 'fieldTypeName',
                                    id: "fieldTypeName",
                                    store: data[i].data.selectOptions.list,
                                    valueField: 'id',
                                    displayField: 'name',
                                    typeAhead: true,
                                    allowBlank: false,
                                    mode: 'local',
                                    selectOnFocus: true,
                                    triggerAction: 'all',
                                    emptyText: 'Survey Field Type',

                                    disabled: this.existingField,
                                    width: 190,
                                    listeners: {
                                        'select': function(combo, newValue, oldValue) {

                                            var iComboValue = combo.getValue();
                                            if (newValue.data.name == "111111111111111") {
                                                newLabel = questionStore2.data.items[0].data.name;
                                                if (!Ext.getCmp('fieldTypeName').rendered) {
                                                    Ext.getCmp('fieldTypeName').fieldLabel = newLabel;
                                                } else {
                                                    Ext.getCmp('fieldTypeName').label.update(newLabel);
                                                }
                                            }
                                        }
                                    }
                                }]
                            }]
                        }]
                    }],
                    buttons: [{
                        id: 'add-button',
                        text: 'Default-Save',
                        disabled: !Ext.getCmp('survey-field-win').canEdit,
                        handler: function() {
                            alert("testing");
                        },
                        scope: this
                    }, {
                        text: 'Default-Cancel',
                        handler: function() {
                            alert("testing-close");
                        },
                        scope: this
                    }]

                }
            );
            example.SurveyFieldDefaultWindow.superclass.initComponent.apply(this, arguments);
        }

    },
    checkEditPermissions: function() {
        return Security.hasAccess("Surveys", Security.UPDATE_ACCESS);
    }

});
Ext.reg('exxample.SurveyFieldDefaultWindow', example.SurveyFieldDefaultWindow);

questionStore2.data.items对象的内容

questionStore2.data.items [sbdata:Objectid:2720json:Objectstore:Ext.data.Store.Ext.extend.constructor__proto __:F,sb,sb]

当我运行此代码时,我得到了唯一一个带有最后一个元素名称和选项列表的组合框。

P.S:我是完全的菜鸟。

0 个答案:

没有答案