Extjs4,如何获取文本字段值

时间:2012-03-01 20:17:23

标签: extjs4

我在获取textField值时遇到问题。

查看:

我有Toobar变量,我添加到我的面板的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!!!! @.@

                }
            }
        });
    },

有谁知道我做错了什么?

如果您在我的代码中发现了错误,请告诉我。

谢谢!

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:3)

允许使用另一种类型的脚本:

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