2
我正在extjs中工作。我有一个textarea的输入字和一个搜索button.I有观点原样在extjs4如何在控制器中捕捉textarea的按键事件
Ext.define('Balaee.view.kp.Word.Word', {
extend : 'Ext.form.Panel',
id : 'WordId',
alias : 'widget.Word',
title : 'Dictionary',
height : 500,
items : [{
xtype : 'textfield',
fieldLabel : 'Enter the word',
name : 'wordtext',
//anchor:'100%',
allowBlank : false,
emptyText : 'Enter the word',
enableKeyEvents : true,
id : 'wordtext',
action : 'EnterAction'
},
{
xtype : 'button',
formBind : true,
fieldLabel : 'Search',
action : 'SearchAction',
text : 'Search'
}
]
});
而且在控制器我有功能原样
SearchWord:function(button)
{
var j = Ext.getCmp('wordtext').getValue();
console.log("word is:"+j);
var answers = '{"data":[';
answers = answers + '{"word":"'+j+'"}'
answers =answers+']}';
console.log(answers);
var storeObject=this.getStore('kp.WordStore');
storeObject.load({
params:{
data: answers
},
callback: function(records,operation,success){
//console.log(records)
},
scope:this
});
var temp=Ext.getCmp('WordId');
temp.remove('WordInfoId');
var details=Ext.create('Balaee.view.kp.Word.WordInfo');
//details.region='center';
temp.add(details);
}
});
现在,上述功能是否正常工作,当用户正在输入的字在textarea中点击提交按钮。但是我想执行上面的“SearchWord”控制器的功能就进入按钮点击了。即如果用户将在textarea中输入单词并按回车键,则需要执行控制器的相同功能。那么如何在控制器中捕捉textarea的回车键按下事件?
下面是一些有用的链接:http://gabbpuy.blogspot.com/2010/02/adding-submit-on-enter- in-extjs.html,http://stackoverflow.com/questions/11682175/extjs-simulate-tab-on-enter-keypress,http://www.phs4j.com/2011/05/how-to-process-在输入键与 - ExtJS的/ – cclerville 2013-04-09 13:37:41