ng-repeat order只改变一次

时间:2014-11-23 20:26:43

标签: javascript angularjs angularjs-scope

我正在尝试使用Angular创建一个表,该表具有可以设置顺序的标题,到目前为止它仍在工作,但它只设置了一次。

我使用了console.log,变量正在改变。

<table class="table table-striped table-bordered">
    <thead>
        <tr>
            <th ng-click="setOrder('iss.issueID')"> ID</th>
            <th ng-click="setOrder('iss.issueTitle')" >Issue</th>
            <th ng-click="setOrder('iss.zone')">Zone</th>
            <th ng-click="setOrder('iss.type')">Type</th>
            <th ng-click="setOrder('iss.time')">Time</th>
            <th ng-click="setOrder('iss.userID')">User ID</th>
            <th ng-click="setOrder('iss.user')">User</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat= "iss in issues | filter:name | orderBy:order">
            <td>{{ iss.issueID }}</td>
            <td>{{ iss.issueTitle }}</td>
            <td>{{ iss.zone }}</td>
            <td>{{ iss.type }}</td>
            <td>{{iss.time * 1000 | date:'yyyy-MM-dd HH:mm:ss '}}</td>
            <td>{{ iss.userID }}</td>
            <td>{{ iss.user }}</td>
        </tr>
   </tbody>
</table>

功能

$scope.issues = [

    <? php

         $result = mysqli_query($con, $qr);
         while ($row = mysqli_fetch_array($result)) {

             echo "{issueID: '".$row['issueID']."', 
                 user: '".$row['firstName'].' '.$row['lastName']."', 
                 userID: '".$row['userID']."',
                 issueTitle: '".$row['issue']."', 
                 issueDesc: '".$row['issueDesc']."', 
                 time: '".$row['timeReceived']."',
                 machine: '".$row['machineID'].' '.$row['manufacturer'].' '.$row['machineType']."',
                 zone: '".$row['zoneID'].' '.$row['Location'].' '.$row['Name']."',
                 type: '".$row['type']."',
                 technician: '".$row['techID']." ".$row['tfirstName']." ".$row['tlastName']."'";
             echo "},";
         }

     ?> 
];

$scope.setOrder = function (order) {
    $scope.order = order;
    console.log($scope.order = order);
};
});

1 个答案:

答案 0 :(得分:2)

您将错误的值传递给setOrder函数。

您应该删除iss.部分。您只需要对象的实际键名。

<tr>
    <th ng-click="setOrder('issueID')"> ID</th>
    <th ng-click="setOrder('issueTitle')" >Issue</th>
    <th ng-click="setOrder('zone')">Zone</th>
    <th ng-click="setOrder('type')">Type</th>
    <th ng-click="setOrder('time')">Time</th>
    <th ng-click="setOrder('userID')">User ID</th>
    <th ng-click="setOrder('user')">User</th>
</tr>

http://plnkr.co/edit/Afh8ha5F7zBgGa2CaO4o?p=preview

演示