Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript angularJS中继器中的错误键_Javascript_Angularjs_Repeater_Angularjs Ng Repeat - Fatal编程技术网

Javascript angularJS中继器中的错误键

Javascript angularJS中继器中的错误键,javascript,angularjs,repeater,angularjs-ng-repeat,Javascript,Angularjs,Repeater,Angularjs Ng Repeat,我有数据: [Object, Object, Object] 0: Object $$hashKey: "007" amount: "123111" name: "test" number: "5" position: "ttt" 1: Object $$hashKey: "006" amount: "123111" name: "test4" number: "4" position: "поз" 2:

我有数据:

[Object, Object, Object]
  0: Object
    $$hashKey: "007"
    amount: "123111"
    name: "test"
    number: "5"
    position: "ttt"
  1: Object
    $$hashKey: "006"
    amount: "123111"
    name: "test4"
    number: "4"
    position: "поз"
  2: Object
    $$hashKey: "005"
    amount: "34555"
    name: "еее"
    number: "1"
    position: "вапвап"
我有一个html格式的repeater:

<tr ng-repeat="(key, player) in players | orderBy:'number'">
    <td>{{key}} - {{player.number}}</td>
    <td>{{player.name}}</td>
    <td>{{player.position}}</td>
    <td>{{player.amount}}</td>
    <td>
        <button ng-click="edit(key)" class="btn btn-primary"><span class="glyphicon glyphicon-edit"></span></button>
        <button ng-click="delete(key)" class="btn btn-danger"><span class="glyphicon glyphicon-floppy-remove"></span></button>
    </td>
</tr>
但我需要:

2 - 1   еее вапвап  34555     
1 - 4   test4   поз 123111    
0 - 5   test    ttt 123111

你不能。列表值的顺序会发生变化,这意味着在使用ng repeat查看每个索引之前,您将获得每个索引的新值。您应该将索引设置为播放机的属性。然后使用该属性

for(var i in players) {
    players[i].index = i;
}
在ng内重复:

{{getRealId(player.$$hashKey)}}


谢谢这是个问题。这些数据直接连接到远程存储库,并在范围内更改它们。我将更改远程数据,我可以找到一些方法来更正密钥吗?例如一个函数,甚至一次-不改变数据结构?我想我可以使用$$hashKey属性这个唯一的-在players数组中搜索当前播放器的键。不幸的是,更改数据结构对我没有好处。不管怎样,谢谢。钥匙从哪里来?它没有在对象结构中定义。为什么不只是editplayer?谢谢!这对我来说太好了
$scope.getRealId = function(hashKey) {
    for (var i in $scope.players) {
        if ($scope.players[i].$$hashKey === hashKey) {
            return i;
        }
    }
};
{{getRealId(player.$$hashKey)}}
<button ng-click="edit(getRealId(player.$$hashKey))" class="btn btn-primary"><span class="glyphicon glyphicon-edit"></span></button>