【问题标题】:Extjs 4 get form IdExtjs 4 获取表单 ID
【发布时间】:2013-11-24 18:08:37
【问题描述】:

我使用的是 Extjs 4.2,下面是代码。我已经定义了表单 ID,但是按钮事件无法获取值。奇怪的是,当我提交表单时,它会转到服务器端,我可以获得字段值。

ID如何取值?

Ext.define('App.view.QuestionForm',{
    extend      : 'Ext.form.Panel',
    alias       : 'widget.QuestionForm',
    requires    : ['Ext.data.Store'],

    bodyPadding  : 5,  
    defaults  : {xtype  : 'textfield' },

    id: 'question_form',

    initComponent   : function(){
        var me = this;
        //me.id = 'question_form';

        me.items = me.buildItems();
        me.dockedItems = me.buildToolbars();
        me.callParent();
    },


    buildItems : function(){
        return [
        {
            fieldLabel: 'ID',  
            name: 'id',
            xtype: 'textfield', 
            anchor: '100%'
        },        
        ];
    },
    buildToolbars : function(){
        return [{
            xtype : 'toolbar',
            dock: 'top',
            items : [

            {
                xtype: 'button', 
                text:'Save', 
                handler: function(){
                    var form = this.up('form').getForm();
                     console.log("form :"+form.id); //undefined 

                    form.submit({url: 'rs/question/save'});                
                }
            },       


            ]
        }];
    }

});

谢谢

【问题讨论】:

  • 你用什么代替了上面的代码?对于this.up('form').getForm();,我收到相同的错误undefined

标签: extjs


【解决方案1】:

您定义 Ext.form.Panel 组件的 id。 所以在处理程序中只需使用:

var form = this.up('form');

用于获取Ext.form.Panel 组件的实例。

当您调用 Ext.form.Panel 组件的方法 getForm() 时,它会返回没有定义 ID 的底层 Ext.form.Basic 组件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    • 2013-02-13
    • 2012-03-29
    • 1970-01-01
    • 2013-01-21
    • 2018-12-21
    • 2023-04-03
    相关资源
    最近更新 更多