如何动态添加字段配置?

Mep*_*pps 7 extjs extjs4

当我点击树面板中的节点时,我想添加允许空白的配置!如果node是一个叶子,我想把name字段的配置:allowBlank:false,如果不是叶子,则makeBlank: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'
        }
Run Code Online (Sandbox Code Playgroud)

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

Gik*_*itt 15

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


It *_*unt 5

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

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

Ext.apply(combo, {your config object});
Run Code Online (Sandbox Code Playgroud)

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

  • 它不一定是.如果你知道你的DOM id是什么,你可以使用Ext.getCmp('myDomID')得到它的引用; (2认同)