Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.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/database/10.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_Html_Angularjs - Fatal编程技术网

Javascript AngularJs中的网格排序

Javascript AngularJs中的网格排序,javascript,html,angularjs,Javascript,Html,Angularjs,我对AngularJs很陌生。 我使用ng repeat获得表中的数据。 现在,我正在尝试对表列进行排序。它没有发生。 请给我建议 <html ng-app="authorsApp"> <div ng-controller="myAuthors"> <table class="table table-striped table-hover"> <tr> <th n

我对AngularJs很陌生。 我使用ng repeat获得表中的数据。 现在,我正在尝试对表列进行排序。它没有发生。 请给我建议

<html ng-app="authorsApp">
    <div ng-controller="myAuthors">
        <table class="table table-striped table-hover">
            <tr>
                <th ng-click="sort{'name'}">
                Name
                <span class="glyphicon glyphicon-sort" ng-show="sortKey == 'name'" ng-class="{'glyphicon-chevron-up':reverse, 'glyphicon-chevron-down':!reverse}"></span>
                </th>
                <th ng-click="sort{'department'}">
                Deparment
                <span class="glyphicon glyphicon-sort" ng-show="sortKey == 'department'" ng-class="{'glyphicon-chevron-up':reverse, 'glyphicon-chevron-down':!reverse}"></span>
                </th>
            </tr>
            <tr ng-repeat="auther in authors | filter: search | orderBy:sortKey:reverse">
                <td>{{auther.name}}</td>
                <td>{{auther.department}}</td>
            </tr>
        </table>
    </div>
    <script src="Scripts/angular.js"></script>
    <script src="Assets/js/authors-01.js"></script>
</html>
json文件如下

var app = angular.module("authorsApp", []);

app.controller("myAuthors", function ($scope, $http) {
    $scope.authors = [];
    $http.get('Assets/js/authors-01.json').then(function (response) {
        $scope.authors = response.data;
    });

    $scope.sort = function (keyname) {
        $scope.sortKey = keyname;
        $scope.reverse = !$scope.reverse;
    }
});
[
    {
        "name": "Manoj",
        "department": "Design"
    },
    {
        "name": "Srikant",
        "department": "Business"
    }
]

提前感谢。

在视图中,如注释中所设置的,您应该调用
sort()
,而不是
sort{}

代码示例:

angular
.module(“authorsApp”,[])
.controller(“myAuthors”,函数($scope){
//代码示例的作者。。。
$scope.authors=[{“name”:“Manoj”,“department”:“Design”},{“name”:“Srikant”,“department”:“Business”}];
$scope.sort=函数(键名){
$scope.sortKey=keyname;
$scope.reverse=!$scope.reverse;
}
});
th{光标:指针;}

名称
部门
{{auther.name}
{{作者部门}

使用
排序(…)调用函数
排序{…}
@tanmya,你能再解释一下吗!!函数调用是用括号
(…)
而不是大括号
{…}
进行的,因此它应该是
sort('name')
@tanmya,而不是$scope.sort=function(keyname){$scope.sortKey=keyname;$scope.reverse=!$scope.reverse;}我应该使用$scope.sort=function(keyname)($scope.sortKey=keyname;$scope.reverse=!$scope.reverse;)请提示我。我已经做了更改,正在运行。谢谢。