如何动态添加字段配置?

时间:2011-05-23 14:27:54

标签: extjs extjs4

当我点击树面板中的节点时,我想添加允许空白的配置! 如果node是一个叶子,我想把name字段的config:allowBlank:false 如果不是叶子,则allowBlank:true。 我没有找到方法来做到这一点?!

非常感谢:)


感谢您的回答,但我的组合框不是全局变量:

var monPrepanel = Ext.create('Ext.form.Panel',{

        frame : true,
        title : 'Editing Zone',
        //renderTo : 'mesfields',
        //width : 750,
        forceFit : true,

        items: [{

                xtype:'fieldset',
                title: 'Add Task : ',
                margin : '20 20 20 20',

                collapsible: true,
                defaultType: 'textfield',
                defaults: {anchor: '100%'},
                layout: 'anchor',
                items: [ {

                itemId : 'p0',
                allowBlank : false,


         xtype : 'textfield',
    anchor : '60%',

         padding : '0 30 0 30',
          fieldLabel : 'Task',

          name : 'task'
        } , {

                itemId : 'p1',
                allowBlank : false,


         xtype : 'combobox',
            anchor : '40%',
            store : materialstore,
            queryMode: 'local',
            displayField: 'data',
            width : 50,
            valueField: 'data',
            editable : false,

         padding : '0 30 0 30',
          fieldLabel : 'Material',

          name : 'material'
        } , {

                allowBlank : true,

         xtype : 'combobox',
            anchor : '40%',
            store : ccstore,
            queryMode: 'local',
            displayField: 'data',
            width : 50,
            valueField: 'data',
            editable : false,

         padding : '0 30 0 30',
          fieldLabel : 'CC',

          name : 'cc'
        }

我需要通过id访问组合框组件吗? 是否有解决方案可以将此组件转换为项目项目?

2 个答案:

答案 0 :(得分:15)

为所需的组合框设置id属性(id: 'anyId'),然后使用Ext.apply(Ext.getCmp('anyId'), {your config object});

答案 1 :(得分:5)

通常,这是您将更改“应用”到已创建的Ext组件的方式。

var combo = new Ext.form.ComboBox({some initial config});

Ext.apply(combo, {your config object});

你是如何加载你的Treenodes的?如果它来自后端,那么你可能会通过从后端添加这些属性来做得更好。