Reading a form-field in sencha touch extjs
I have a form field and i want to read the text entered into it, i tried the following code:
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.getRec开发者_如何学Pythonord();
console.log(currentText);
},
you may try this:
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);
},
To get the value of a textfield, use the field's getValue() method.
For example:
var field = myTextField;
var currentText = field.getValue();
You can also use searchfield
instead of textfield
. It also has the getValue() method available.
精彩评论