1

我有一个表单字段,我想阅读输入其中的文本,我尝试了以下代码:

this.searchButton = new Ext.Button({// The button press will invoke the search action
            text: 'Go',
            handler: this.searchButtonTap,
            scope: this
        });

this.topToolbar = new Ext.form.FormPanel({
                   items: [

                    {xtype: 'textfield',
                    name: 'search',
                    placeHolder: 'Search'},
                    this.searchButton

                ]
        });

 searchButtonTap: function () {
       // console.log(this.topToolbar.items.items[1]);
       var currentText = AsApp.views.AsListView.getRecord();
        console.log(currentText);
    },
4

2 回答 2

1

你可以试试这个:

this.searchField = new Ext.form.Text({
            displayField: 'name',
            valueField: 'name',
            editable: true,
            forceSelection: true,
            triggerAction: 'all',
            emptyText: 'Search...',
            selectOnFocus: true
    });

this.searchButton = new Ext.Button({// The button press will invoke the search action
        text: 'Go',
        handler: this.searchButtonTap,
        scope: this
    });

    this.topToolbar = new Ext.Toolbar({
                   items: [
                { xtype: 'spacer' },    
                    this.searchField,
                    this.searchButton,
                    { xtype: 'spacer' },
                ]
        });



searchButtonTap: function () {
    var searchText = this.searchField.getValue();
    console.log(searchText);

    },
于 2011-09-02T21:25:59.980 回答
0

要获取文本字段的值,请使用该字段的 getValue() 方法。

例如:

var field = myTextField;
var currentText = field.getValue();

您也可以使用searchfield代替textfield. 它还具有可用的 getValue() 方法。

于 2011-09-02T17:01:43.220 回答