Ich habe ein zweidimensionales Array von Cell-Objekten, dieses Array ist in meinem HTML durch einige ng-repeat <td>
Elemente, Ich möchte meine Zellen aktualisieren, wenn ein <td>
Klicken Sie auf. Ich weiß nicht, wie ich meine <td>
an die entsprechenden Zellen in meinem Array binden kann.
Das ist, was ich versuchte, tut es mir irgendwelche Fehler gibt, wird das Array in dem HTML-Code angezeigt, aber die ng-Klick Ereignis nicht funktioniert:
html:Update Array-Modell mit einem Klick auf ng-Repeat-Elemente
<div ng-app = "game" ng-controller = "gameCtrl" id = "gameLayout">
<div id = "boardLayout">
<table id = "grid">
<tr ng-repeat = "y in grid">
<td ng-repeat = "x in y" ng-model = "grid[y][x]" ng-click = "grid[y][x].tryPlay(game)"></td>
</tr>
</table>
</div>
</div>
Javascript:
Cell.prototype.tryPlay = function(game)
{
console.log("tryPlay call.");
}
// ...
var game = angular.module("game", []);
game.controller("gameCtrl", function($scope, $interval)
{
var grid = [[new Cell(), new Cell(), new Cell(), new Cell(), new Cell()],
[new Cell(), new Cell(), new Cell(), new Cell(), new Cell()],
[new Cell(), new Cell(), new Cell(), new Cell(), new Cell()],
[new Cell(), new Cell(), new Cell(), new Cell(), new Cell()],
[new Cell(), new Cell(), new Cell(), new Cell(), new Cell()]];
var game = new Game(grid);
$scope.game = game;
$scope.grid = game.grid;
});
Danke, ich weiß nicht, warum ich gedacht habe, dass x und y Indizes sind, wenn man 'y in grid 'liest, ist es offensichtlich, dass es sich um Objekte handelt. – aurelienC