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