【问题标题】:How to adding field's config on the fly?如何动态添加字段的配置?
【发布时间】:2017-08-08 16:32:57
【问题描述】:

当我单击树面板中的节点时,我想添加 allow Blanks 的配置! 如果节点是叶子,我想输入名称字段的配置: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 访问组合框组件吗? 有没有解决方案可以将此组件访问到项目到项目?

【问题讨论】:

    标签: extjs extjs4


    【解决方案1】:

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

    【讨论】:

    • 如何获取现有配置,能否将{your config object}替换为现有配置
    【解决方案2】:

    一般来说,这就是您如何将更改“应用”到您已经创建的 Ext 组件。

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

    你是如何加载你的树节点的?如果从后端添加这些属性,您可能会做得更好。

    【讨论】:

    • 感谢您的回答,但我的组合框不是全局变量
    • 不必如此。如果你知道你的 DOM id 是什么,你可以使用 Ext.getCmp('myDomID');
    • 这种“应用”技术是否也适用于那些改变组件布局的配置。例如,Ext.form.FieldSet 可折叠属性在呈现后设置为 true。在我的情况下,布局没有更新: Ext.apply(fieldset,{collapsible:true, style: "background:red"});
    • 这会更新对象的配置。但是,您可能需要在组件所在的容器上调用 doLayout()。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-09
    • 2014-07-09
    • 2011-04-08
    • 2018-06-19
    • 1970-01-01
    • 1970-01-01
    • 2013-05-31
    相关资源
    最近更新 更多