2012-08-08 75 views
0

我嘗試使用Ext.ComponentManager設置值,但它不起作用。這是我的代碼..我想從id設置firstname的值。我從服務器獲取id值,但無法在名字和姓氏字段中進行設置。請幫忙。無法在Ext.window.Window中設置值

Ext.define('sample.view.student.Edit', { 
extend : 'Ext.window.Window', 
alias : 'widget.studentedit', 




requires : ['Ext.form.Panel', 'Ext.form.field.Text', 
     'Ext.form.field.ComboBox'], 




title : 'student dtls', 
layout : 'fit', 
autoShow : true, 
width : 280, 




iconCls : 'icon-user', 




initComponent : function() { 
    this.items = [{ 
     xtype : 'form', 
     padding : '5 5 0 5', 
     border : false, 
     style : 'background-color: #fff;', 




     fieldDefaults : { 
      anchor : '100%', 
      labelAlign : 'left', 
      allowBlank : false, 
      combineErrors : true, 
      msgTarget : 'side' 
     }, 




     items : [ { 
        xtype : 'textfield', 
        name : 'studentId', 
        fieldLabel : 'studentId', 
        listeners : { 
         blur : function() { 
          // fnDataForm(this.value); 
          Ext.Ajax.request({ 
           url : 'student/fetchDtls.action', 
           params : { 
            guiInstrId : this.value 
           }, 
           success : function(response, opts) { 
            var jsonResp = Ext 
              .decode(response.responseText); 




            console.dir(jsonResp); 
            console.log(jsonResp.studentFirstName); 
            // How to set jsonResp.studentFirstName value in below textfield ? 
            this.up('form').getForm().getValues().studentFirstName.setValue(jsonResp.studentFirstName); 
           }, 
           failure : function(response, opts) { 
            console 
              .log('server-side failure with status code ' 
                + response.status); 
           } 
          }); 
         } 
        } 




       }, { 
        xtype : 'textfield', 
        name : 'studentFirstName', 
        fieldLabel : 'student First Name' 




       }, { 
        xtype : 'textfield', 
        name : 'studentLastName', 
        fieldLabel : 'student Last Name' 




       }] 
    }]; 

回答

2

我不得不把這個放在我的代碼中,然後它就像魅力一樣工作。讓我知道,如果任何人也有同樣的問題..它可能也會幫助你...

{ 
xtype: 'textfield', 
name: 'studentFirstName', 
itemId: 'studentfirstname', 
fieldLabel: 'student First Name' 
} 

.. 

var form = this.up('form'), 
    sfn = form.down('#studentfirstname'); 

sfn.setValue(sonResp.studentFirstName);