我对 AngularJs 非常陌生,并试图将 Smart-Table 插件“包装”在指令中。我可以得到行但没有显示分页
目前这就是我所做的。
app.directive('grid', [ function () {
return {
restrict: 'E',
replace: true,
template: function (element, attrs) {
return '<table class="table table-striped">'
+ '<thead>'
+ ' <tr>'
+ '<th st-ratio="20" st-sort="Team">Team</th>'
+ '<th st-ratio="20" st-sort="TeamFreq">Team Freq</th>'
+ '<th st-ratio="10" st-sort="TeamSac">Team Sac</th>'
+ '<th st-ratio="30" st-sort="Priority">Priority</th>'
+ '</tr>'
+ '</thead>'
+ '<tbody>'
+ '<tr ng-repeat="row in dataset">'
+ ' <td>{{row.firstName}}</td>'
+ '<td>{{row.lastName | uppercase}}</td>'
+ '<td>{{row.age}}</td>'
+ '<td>{{row.email}}</td>'
+ '</tr>'
+ '</tbody>'
+ '<tfoot>'
+ '<tr>'
+ '<td colspan="4" class="text-center">'
+ '<div class="pagination pagination-xs m-top-none pull-right" st-pagination="1" st-items-by-page="itemsByPage" st-displayed-pages="4"></div>'
+ '</td>'
+ '</tr>'
+ '</tfoot>'
+ '</table>';
},
scope: {
},
controller: function ($scope) {
},
link: function (scope, elem, attrs) {
var nameList = ['Pierre', 'Pol', 'Jacques', 'Robert', 'Elisa'], familyName = ['Dupont', 'Germain', 'Delcourt', 'bjip', 'Menez'];
function createRandomItem() {
var
firstName = nameList[Math.floor(Math.random() * 4)],
lastName = familyName[Math.floor(Math.random() * 4)],
age = Math.floor(Math.random() * 100),
email = firstName + lastName + '@@whatever.com',
balance = Math.random() * 3000;
return {
firstName: firstName,
lastName: lastName,
age: age,
email: email,
balance: balance
};
}
scope.rowCollection = [];
for (var j = 0; j < 10; j++) {
scope.rowCollection.push(createRandomItem());
}
scope.dataset = [].concat(scope.rowCollection);
}
};
}]);
我的 html 包含这个标签
<grid st-table="dataset"></grid>
这段代码只是一个测试,数据将使用服务传递......并且模板将是动态的。我需要一些帮助 :-)
谢谢