0
我已經從類似問題的人那裏看過多個問題線索,但他們沒有解決我的問題。Ng-repeat不更新視圖
這是全碼(Exluding的CSS部分:
<script>
var app = angular.module("game", []);
app.controller("controlematrix",function($scope)
{
$scope.undo = [];
$scope.matriz = [ 2,2,2,2,2,2,2
,2,2,2,0,0,0,2
,2,3,0,0,0,0,2
,2,0,0,0,0,0,2
,2,3,0,0,2,0,2
,2,0,0,0,0,0,2
,2,2,2,2,2,2,2];
$scope.posx = 5;
$scope.posy = 3;
$scope.testeshow= function(atual){
return (($scope.posx + $scope.posy * 7) != atual);
}
$scope.up = function() {
if($scope.matriz[$scope.posx + ($scope.posy-1) * 7] != 2)
{
$scope.posy--;
}
}
$scope.down = function() {
if($scope.matriz[$scope.posx + ($scope.posy+1) * 7] != 2)
{
$scope.posy++;
}
}
$scope.left = function() {
if($scope.matriz[($scope.posx-1) + $scope.posy * 7] != 2)
{
$scope.posx--;
}
}
$scope.right = function() {
if($scope.matriz[($scope.posx+1) + $scope.posy * 7] != 2)
{
$scope.posx++;
}
}
});
</script>
<div id="everything" ng-app="game" ng-controller="controlematrix" >
<div id="container">
<div class="item" ng-repeat= "x in matriz track by $index">
<img ng-src="{{'tile' + x +'.png'}}" alt="tile" ng-show= "{{testeshow($index)}}">
<img ng-src="player.png" alt="player" ng-show= "{{!testeshow($index)}}">
</div>
</div>
<div id="buttonscreen">
<button class="botao" ng-click="up()">UP</button>
<button class="botao" ng-click="down()">DOWN</button>
<button class="botao" ng-click="left()">LEFT</button>
<button class="botao" ng-click="right()">RIGHT</button>
</div>
</div>
調試之後,似乎POSX和POSY值更新等他們應該但屏幕上的圖像保持不變。我似乎無法找到概率lem是。如果有人能幫忙,我會非常感激。
如果您的答案與其他人不同,請寫下答案。謝謝 –