无法在sencha中获得对表单的引用

时间:2014-03-14 15:05:17

标签: forms extjs ext4

我正在尝试重置表单,点击按钮。 按钮的功能在文件单独的控制器文件中定义。 但点击按钮重置我得到错误 “未捕获的TypeError:对象form1orig没有方法'重置'”

Controller
    Ext.define('myapp.controller.form1', {
    extend: 'Ext.app.Controller',
    requires: [
    'myapp.view.form1'
    ],
    config: {
        refs: {
        form1orig: '#pressc',
        form1Submit: 'button[action=sub]',
        form1Reset: 'button[action=res]'
          },
    control: {
    'form1Reset' : {
      tap: 'onForm1Reset'
    },
  'form1Submit' : {
      tap: 'onForm1Submit'
    }     
    }
},

onForm1Reset: function(button){
  'form1orig'.reset();
  console.log('Tapped reset');

},
  onForm1Submit: function(button){

console.log('Tapped submit');

}

});

查看

Ext.define('myapp.view.form1', {
extend: 'Ext.form.Panel',

requires: [
    'Ext.form.FieldSet',
],
xtype: 'form1Me',
id: 'form1Me',
config: {
    items: [
        {
            xtype: 'fieldset',
            id: 'pressc',
            instructions: 'Please enter the information above.',
            defaults: {
                labelWidth: '35%'
            },
            items: [
                {
          xtype:'textfield',
          name: 'name',
          label: 'Name',
          id: 'eman',
          placeHolder: 'Name'
        },

        {
                    xtype: 'textareafield',
                    name : 'Prescription',
        id: 'pres',
                    label: 'Prescription',
                    placeHolder: 'Enter your prescription here...'          
                }
            ]
        },

        {
            xtype: 'container',
            defaults: {
                xtype: 'button',
                style: 'margin: .5em',
                flex : 1
            },
            layout: {
                type: 'hbox'
            },
            items: [
                {

          text: 'Submit',
          id: 'subMe',
          action: 'sub',
                    scope: this,
                    hasDisabled: false
                    //handler: function(btn){

          /*var presscForm = Ext.getCmp('presscForm');
          presscForm.submit({
            url: '../../result.php',
            method: 'POST', 
            success: function() {
              alert('Thamk you for using our service');
            }
          });*/
          //}
                },
                {
                    text: 'Reset',
        id: 'resMe',
        action: 'res'
                    /*handler: function(){
                        Ext.getCmp('form1Me').reset();
                    }*/
                }
            ]
        }
    ]
}
});

帮助

1 个答案:

答案 0 :(得分:0)

您应该执行以下操作:

var form = Ext.ComponentQuery.query('form1Me');
form.reset();