나는 포크와 Plunker을 업데이트했습니다. 실제로 사용자 지정 지시문을 사용하여 같은 종류의 테이블을 만들었습니다. 테이블을 만들려면 의미 론적 마크 업을 사용해야합니다. 그것이 내가 귀하의 HTML을 수정 한 이유입니다.
그런 다음 select-me
지시문을 업데이트하여 클릭 할 때 자동 선택을 수행 한 방법과 화살표 키 탐색을 구현 한 방법을 보여줍니다.
Updated Plunker
layout.html
<table>
<thead>
<tr ng-repeat="element in header" class="header-cells" style="width:{{element.width}}px">
<th>{{element.column}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="element in body" data-indexrow="{{$index}}">
<td ng-repeat="h in header" class="custom-row" data-indexcol="{{$index}}">
<input type="text" ng-model="element[h.column]" class="body-cell" style="width:{{h.width}}px" select-me>
</td>
</tr>
</tbody>
</table>
selectMe 지침 (JS)
ct.directive("selectMe", function() {
return ({
restrict: "A",
// templateUrl: 'sortdropdown.html',
link: link
});
function link(scope, element, attributes) {
element.on('click', function(e) {
element.select();
});
element.on('keyup', function(e) {
var $input = angular.element(this),
$td = $input.parent(),
$tr = $td.parent(),
indexrow = parseInt($tr.attr('data-indexrow'),10),
indexcol = parseInt($td.attr('data-indexcol'),10);
console.log(indexrow);
console.log(indexcol);
// up arrow
if (e.keyCode === 38) {
//move up
}
// down arrow
if (e.keyCode === 40) {
//move down
}
// left arrow
if (e.keyCode === 37) {
//move left
}
// right arrow
if (e.keyCode === 39) {
//move right
}
});
}
});
감사 glepretre .. 그 정도로 간단한 모양과 작동 – runtimeZero
@ glepretre..could 너는 내가 세포들 사이에서 어떻게 움직임을 도입 할 수 있는지 조언한다. – runtimeZero
@JamesHans 행과 열의 특성을 색인에 추가했습니다. 그리고 지시어에 넣는 방법을 보여주었습니다. jQlite 또는 jQuery로 이동하고 특정 사례 (첫 번째 줄과 마지막 줄, 열에 대한 idem)를 처리 할 수있는 적절한 입력을 얻을 수있게했습니다. ;) 나를 투표 해주세요. 잊지 마세요. :피 – glepretre