我有以下自定义标记/指令:
<tile class="ng-scope gridster-item" tilevalue="1" gridster-item="tile" row="0" col = "0" ng-repeat="tile in selectedTiles"> </tile>
Run Code Online (Sandbox Code Playgroud)
我创建了一个键盘控件,其目标是关注selectedTiles array每个键盘事件中的每个tile("tile"指令)(shift + right arrow).
// Keyboard Tile Navigation
//Starting pos
var curIndex = -1
//keyboard control
$(document).keydown(function(event) {
if (event.shiftKey && event.which === 39) {
console.log("right");
focusNext();
}
});
function focusNext() {
focusTile(+1);
}
function focusTile(delta) {
var visibleTiles = $scope.selectedTiles;
var elem = $("[gridster-item='tile']");
curIndex = curIndex + delta;
el = elem[curIndex];
el.attr('tabindex', -1).focus();
el.css("border-color", "yellow");
}
Run Code Online (Sandbox Code Playgroud)
当我得到变量的控制台日志时,elem我得到了dom中出现的tile数组(如预期的那样).问题是当我尝试添加一个 …