2012-03-01 93 views
1

我有一个获取textField值的问题。Extjs4,如何获得文本字段值

查看:

我有商工具栏变量,我添加到我的TBAR面板。

var orderListTbar = Ext.create('Ext.Toolbar',{ 
    id : 'orderListTbar', 
    items : [ 
     '',{ 
      xtype : 'radiofield', 
      name : 'searchType', 
      value : 'order_name', 
      boxLabel : 'Order Name' 
     },'',{ 
      xtype : 'radiofield', 
      name : 'searchType', 
      value : 'order_no', 
      boxLabel : 'Order No' 
     },'',{ 
      xtype : 'radiofield', 
      name : 'searchType', 
      value : 'status', 
      boxLabel : 'Status' 
     },'=',{ 
      xtype : 'textfield', 
      name : 'keyword', 
      value : 'Keyword' 
     },'|',{ 
      xtype : 'datefield', 
      name : 'order_from', 
      fieldLabel : 'From ', 
      labelWidth : 40, 
      width : 150, 
      value : new Date() 
     },'~',{ 
      xtype : 'datefield', 
      name : 'order_to', 
      fieldLabel : "To ", 
      labelWidth : 40, 
      width : 150, 
      value : new Date() 
     },'|',{ 
      xtype : 'button', 
      name : 'searchBtn', 
      text : "Search" 
     } 
    ] 
}); 

而在我的控制器。我想获得字段值。

init : function(application){   

     this.control({ 
      "#orderListTbar button[name=searchBtn]" : { 
       click : function(){ 
        orderFrom = Ext.ComponentQuery.query('#orderListTbar [name=order_from]'); 
        console.log(orderFrom); // it return Object as well 
        console.log(orderFrom.value); // BUT, it return undefined!!!! @[email protected] 

       } 
      } 
     }); 
    }, 

有人知道我做错了什么吗?

如果您在我的代码中发现错误,请指教我。

谢谢!

+0

,我不知道该用“Ext.ComponentQuery.query()”跟踪领域。如果我错了,请指教我。 – 2012-03-01 20:26:22

回答

3

您应该使用getValue方法代替value属性。 value未在API中列出。 另请注意Ext.ComponentQuery.query返回数组。

+0

我也尝试过getValue(),但错误消息说“orderFrom.getValue不是函数”@。@ – 2012-03-01 21:25:00

+0

我注意到'query'返回数组。尝试'orderFrom [0] .getValue()' – Krzysztof 2012-03-01 21:43:52

+0

哇谢谢你!它返回一个数组! zz – 2012-03-01 21:47:40

3

另一种类型的脚本允许如下:

orderFrom = Ext.ComponentQuery.query("[name=order_from]",orderListTbar);