通常找到的function都是针对一个键的,写下通过首字母定位的code:
var keysOntree = new Array();
var s="abcdefghijklmnopqrstuvwxyz";
var lastText = '';
var nextOK = false;
for(var i=0; i<s.length; i++)
{
var keyChar = s.charAt(i);
var command = 'keysOntree.push({key:\'' + keyChar + '\',fn:function(){' ...
eval(command);
}
上边省略号里的内容其实是以下code(以字母t为例):
keysOntree.push({
key : 't',
fn : function() {
var childNode = root.findChildBy(function(n) {
if(n.attributes.text.toLowerCase().indexOf('t') == 0) {
if(nextOK || (lastText != '' && lastText.toLowerCase().substring(0,1) != 't')) {
lastText = n.attributes.text;
nextOK = false;
return true;
}
if(n.attributes.text == lastText) {
nextOK = true;
return false;
}
}
return false;
});
if(!childNode) {
childNode = root.findChildBy(function(n) {
if(n.attributes.text.toLowerCase().indexOf('t') == 0) {
lastText = n.attributes.text;
nextOK = false;
return true;
}
return false;
});
}
if(childNode) {
childNode.select();
selectedField = childNode;
childNode.ensureVisible();
}
}
});
最后:
var tree = new Ext.tree.TreePanel({
......
keys: keysOntree
});