从对象获取属性值解析HTML

时间:2017-04-23 20:29:37

标签: javascript angularjs object

我正在使用棱角分明。我想要获得一个属性的价值。 这是HTML代码

<tr ng-repeat="player in propertyCtrl.players">
   <td>{{player.name}}</td>
   <td>{{player.money}}</td>
   <td><input type="radio" name="selectedPlayer" value="{{player}}" required="" ng-model="propertyCtrl.player"></td>
</tr>

如您所见,我将播放器的对象传递给控制器​​

propertyCtrl.buy = function(valid) {

    if (valid) {

      var playerObj = propertyCtrl.player;
      var playerMoney =  playerObj.money;
    }
}

我也试过以下内容但没有成功:

var playerMoney =  playerObj[money];

var playerMoney =  playerObj['money'];

我得到的所有尝试&#34;未定义&#34;

任何帮助都非常感谢!

1 个答案:

答案 0 :(得分:1)

我会尝试使用

<tr ng-repeat="player in propertyCtrl.players track by $index">
   <td>{{player.name}}</td>
   <td>{{player.money}}</td>
   <td><input type="radio" name="selectedPlayer" value="{{$index}}" 
            required="" 
            ng-model="propertyCtrl.playerIndex">
   </td>
</tr>

var playerObj = propertyCtrl.players[Number(propertyCtrl.playerIndex)];

我假设players是一个数组。