AngularJS - 从jsonRequest过滤orderBy

时间:2015-07-28 15:14:33

标签: javascript angularjs

我正在尝试按名称命名我的html表中的列。

<tr ng-repeat="setting in detailsExample.versionExample.settings | orderBy:'name'">

这是json我试图用$ filter

连接它
jsonRequest.request('/api/request.php', 'APP', 'GET', dataObj, function (dataReturned) {
    $scope.appDetails.versionDetails = dataReturned.data;
    var orderBy = $filter('orderBy');
    if (isEmpty($scope.appDetails.versionDetails.settings)) {
        $scope.appDetails.versionDetails.settings = {}
        $filter.appDetails.versionDetails.settings = {};
    }
});

我一直在使用AngularJS文档作为指南:https://docs.angularjs.org/api/ng/filter/orderBy

完整代码:https://jsfiddle.net/wky9vrbt/

我的变量有问题吗? var orderBy = $ filter(&#39; orderBy&#39;); ?

1 个答案:

答案 0 :(得分:0)

As you use angular's built-in orderBy filter directly in your HTML view you do not need to do the follwoing call in javascript.

var orderBy = $filter('orderBy');

You can simply remove that line of code.

However, when using the orderBy filter in Javascript, you must specify the array you want to be ordered by specifiing it inside an additional bracket, Here is an example:

$filter('orderBy')($scope.appDetails.versionDetails.settings);