我正在使用angular指令来排序我的表头。但似乎html无法到达我的孤立指令范围内的变量,我似乎无法做出错误。所以我希望你们中的一个人可以帮助我。
myApp.js
var koekoek = angular.module('koekoek', [ 'ui.bootstrap', 'ngRoute', 'sortTableHead']);
sortTableHead.js(固定表头指令)
(function(ng) {
'use strict';
var module = ng.module('sortTableHead', []);
module.directive('sortTableHead', [
function() {
return {
restrict: 'A',
transclude: true,
replace: true,
template: '<th class="selectable" data-ng-click="onClick()" >' +
'<span ng-transclude class="pull-left"></span>' +
'<i class="fa fa-sort pull-right" data-ng-class="{\'fa-sort-desc\' : order === by && !reverse, \'fa-sort-asc\' : order === by && reverse, \'fa-sort\': !order === by}"></i>' +
'</th>',
scope: {
order: '=',
by: '=',
reverse: '='
},
link: function(scope) {
scope.onClick = function() {
if (scope.order === scope.by) {
scope.reverse = !scope.reverse;
} else {
scope.by = scope.order;
scope.reverse = false;
}
}
}
}
}
]);
})(angular);
View.html
<table id="dataTable" class="table table-striped table-hover">
<thead>
<tr>
<th ng-repeat="(key, value) in data[0]" repeat-done="fixedTableHeaders()" sort-table-head by="order" reverse="reverse" order="'ipv4'">
{{ key }}
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in data | orderBy:order:reverse | filter:searchText" ng-click="rowClickHandler(row)">
<td ng-repeat="(varName, value) in row">
{{ value }}
</td>
</tr>
</table>
控制器:
koekoek.controller('serversOverviewController', function($scope, $http, $location) {
$scope.rowClickHandler = function(rowData) {
var selectedRowIp = rowData.ipv4;
$location.path('/overview/' + selectedRowIp);
};
$http.get('server/serverList').success(function(data) {
$scope.data = data;
});
$scope.fixedTableHeaders = function(){
var $table = $("#dataTable");
$table.floatThead({
useAbsolutePositioning: true
});
$table.floatThead('reflow');
};
});
订单现在是硬编码的。