我正在尋找一個上下文菜單指令,可以告訴我實際點擊了什麼,所以我可以對它做出反應。Angularj JS上下文菜單
玩this但該模塊的問題是,我無法弄清楚如何唯一標識被點擊的元素。所以我可以做正確的邏輯就可以了:
我需要的東西,我可以傳遞到回調函數
控制器:
$scope.items.Data = [{Code:'row1', Name:'Name1'},{Code:'row2', Name:'Name2'}]
$scope.items.Actions = [
{
Code: 'Action1',
Name: 'First action'
},
{
Code: 'Action2',
Name: 'Second action'
}
]
var actionList = [];
for (var i = 0; i < $scope.items.Actions.length; i++) {
actionList.push($scope.items.Actions[i].Name, function ($itemScope,$event) {
console.log('Action executed', $scope.objectId, $itemScope,$event,$itemScope.$index);
// Need access to $scope.items.Actions[i].Code or at least the index of the array
});
}
$scope.contextOptions = actionList;
HTML:
<table>
<thead>
<tr>
<td>Code</td>
<td>Name</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in items.Data" context-menu="contextOptions">
<td>{{row.Code}}</td>
<td>{{row.Name}}</td>
</tr>
</tbody>
</table>
你能展示更多的代碼,包括HTML嗎? – cnorthfield
添加了更多的代碼,基本上我需要確定被點擊的操作 – Jester
'$ scope.items'中屬性'Data'的位置? – cnorthfield