我正在尝试更改下面exp中所选对象的点。
$scope.players = [{
name: 'Kobe',
points: 10,
asists: 0,
rebounds: 0
}, {
name: 'Jordan',
points: 20,
asists: 0,
rebounds: 0
}, {
name: 'Grant',
points: 30,
asists: 0,
rebounds: 0
},
];
并指定一个用其名称选择的对象。
if($scope.playerName == $scope.players[i].name){
$scope.selectedPlayerPoints = $scope.players[i].points;
$scope.selectedPlayerAsists = $scope.players[i].asists;
$scope.selectedPlayerRebounds = $scope.players[i].rebounds;
}
但我无法更新它们:
$scope.selectedPlayerPoints.push(playerPoints);
为了更清楚,请检查:http://plnkr.co/edit/B8Nydni586Se79fDpjnq?p=preview
工作原理: 单击一个播放器 双击点=每次添加2点。 3 - 当你添加更多点时,它会动态地改变对象..(但这就是问题..)
Thnx提前!
答案 0 :(得分:0)
我不确定你想要达到什么目标,但我猜你在保存玩家积分方面遇到了麻烦。
我已更新您的plunkr。基本上不是传递原始值:
$scope.selectPlayer = function(name, points, asists, rebounds) { ... }
你应该传递对象引用:
$scope.selectPlayer = function(player) { ... }