好的,花了我一段时间,但弄明白了。我真正想做的是将焦点添加到一行中。这样做的代码在dgrid/Keyboard.js
方法下_focusOnNode
。
将焦点从一行更改为另一行的实际代码currentFocusedNode
是focusedNode
:
if(currentFocusedNode){
// Clean up previously-focused element
// Remove the class name and the tabIndex attribute
put(currentFocusedNode, "!dgrid-focus[!tabIndex]");
if(has("ie") < 8){
// Clean up after workaround below (for non-input cases)
currentFocusedNode.style.position = "";
}
}
if(has("ie") < 8){
// setting the position to relative magically makes the outline
// work properly for focusing later on with old IE.
// (can't be done a priori with CSS or screws up the entire table)
focusedNode.style.position = "relative";
}
focusedNode.tabIndex = grid.tabIndex;
focusedNode.focus();
put(focusedNode, ".dgrid-focus");
上面的代码实际上只是一个代码片段,要使其工作,您必须先声明"dojo/has"
and"put-selector/put"
并定义currentFocusedNode
and focusedNode
。但我把它作为练习留给读者;-)
另请注意,这只会改变“焦点”,它不会选择focusedNode
但可以使用轻松完成grid.select(focusedNode);