1

我的html:

    <table class="table">
        <thead>
        <tr>
            <th><a href="">Name</a></th>
            <th><a href="">Issued shares</a></th>
            <th><a href="">Closing price</a></th>
            <th><a href="" ng-click="predicateBlueChip = 'marketCap()'; reverseBlueChip = !reverseBlueChip">Market capitalisation</a></th>
        </tr>
        </thead>
        <tbody>
        <tr ng-repeat="listing in listings | orderBy:predicateBlueChip:reverseBlueChip">
            <td><a ng-href="#/browse/listing/{{ listing.id }}">{{ listing.name_short }}</a></td>
            <td>{{ listing.last_price.issued_shares }}</td>
            <td>{{ listing.last_price.price_close }}</td>
            <td>{{ marketCap(listing) | currency:'R' }}</td>
        </tr>
        </tbody>
    </table>

控制器:

   $scope.predicateBlueChip = 'marketCap()';
    $scope.reverseBlueChip = true;

    $scope.marketCap = function(listing) {
        return Math.round(listing.last_price.price_close * listing.last_price.issued_shares / 1000000);
    }

orderBy 不起作用,我不确定哪里出错了;关于 orderBy 的许多其他帖子并没有解决我的问题。有什么建议么?

4

1 回答 1

2

表达式应该是一个函数,而不是包含函数调用的字符串。

删除这一行:

$scope.predicateBlueChip = 'marketCap()';

并直接使用marketCap函数:

<tr ng-repeat="listing in listings | orderBy:marketCap:reverseBlueChip">
于 2013-07-13T07:45:07.120 回答