2014-11-25 16 views
0

我有一个按钮,窗口中输入和几个字段我需要得到的数据表单的和有方法上的按钮:记录未定义Extjs4获取数据的表格

enter: function (button) {  
     var win = button.up('window'), 
      form = win.down('form'), 
      record = form.getRecord(), 
      values = form.getValues(); 
     record.set(values); 
     win.close(); 
     this.getUsersStore().sync(); 

这里记录未定义。我做错了什么? ///////////////////////////////////////////////// ///////////////////

下面的形式:

Ext.define('ExtMVC.view.portlet.Login', { 

    extend: 'Ext.window.Window', 
    alias: 'widget.login', 
    layout: 'fit', 
    title: 'LogIn', 
    width: 300, 
    height: 150, 
    autoShow: true, 
    store: 'LoginModels', 

    initComponent: function() { 
     this.items = [ 
      { 
       xtype: 'form',     
       items: [ 
        { 
         xtype: 'textfield', 
         name: 'Name', 
         fieldLabel: 'Name', 
         style: { 'margin': '10px' }, 
        }, 
        { 
         xtype: 'textfield', 
         name: 'Password', 
         fieldLabel: 'Password', 
         style: { 'margin': '10px' }, 
        }      
       ] 
      } 
     ]; 

     this.buttons = [ 
      { 
       text: 'Enter', 
       action: 'enter', 
       //handler: this.enter 
      }, 
      { 
       text: 'Cancel', 
       scope: this, 
       handler: this.close 
      }, 
      { 
       text: 'Sing in', 
       scope: this, 
       handler: this.close 
      } 
     ]; 

     this.callParent(arguments); 


    } 
}); 

回答

1

尝试使用此代码

values=form.getForm().getValues(); 
+0

不工作,设置() - 获取NULL – TimurYakov 2014-11-25 15:59:47

+0

发表您的表单代码 – 2014-11-25 16:08:14

+0

请参见我的文章//// – TimurYakov 2014-11-26 07:29:43

0

您必须更换在通过form.getRecord()获取之前使用form.loadRecord()加载表单,否则form.getRecord()返回undefined。

+0

你是什么意思?我需要写什么? – TimurYakov 2014-11-26 08:11:03

1

请通过转DOC因为它清楚地说:

getRecord():Ext.data.Model: 如果已通过loadRecord加载,则返回当前加载Ext.data.Model实例。

而在你的例子中,我没有看到使用loadRecord()加载你的表单面板的任何代码。

enter: function (button) {  
    var win = button.up('window'), 
     form = win.down('form'),    
     //record = form.getRecord(), /*not required here*/ 
     record = this.getUsersStore().findRecord('id', 1) /*if you know id or some thing which field is know*/ 

     values = form.getValues(); 
    record.set(values); 
    win.close(); 
    this.getUsersStore().sync();