我正在使用Angular-datatable来显示数据,并且它与静态数据一起工作正常,但是当动态提供数据时它不起作用。它让我很难过。
我想要实现的是从
ajax
in加载数据datatable
。
我用于初始化的以下代码及其工作正常Plunker:
function MyChapterController($scope, $q, DTOptionsBuilder, DTColumnBuilder, chapter) {
var vm = this;
vm.dtOptions = DTOptionsBuilder.newOptions()
.withPaginationType('full_numbers')
.withDisplayLength(2)
.withDOM('pitrfl');
vm.dtColumns = [
DTColumnBuilder.newColumn('id').withTitle('ID'),
DTColumnBuilder.newColumn('title').withTitle('First name'),
DTColumnBuilder.newColumn('lastName').withTitle('Last name').notVisible()
];
vm.myChapters = [];
}
这是以下代码不起作用检查Plunker:
function MyChapterController($scope, $q, $resource, DTOptionsBuilder, DTColumnBuilder, chapter) {
var vm = this;
vm.dtOptions = DTOptionsBuilder.newOptions()
.withPaginationType('full_numbers')
.withDisplayLength(2)
.withDOM('pitrfl');
vm.dtColumns = [
DTColumnBuilder.newColumn('id').withTitle('ID'),
DTColumnBuilder.newColumn('title').withTitle('First name'),
DTColumnBuilder.newColumn('lastName').withTitle('Last name').notVisible()
];
vm.myChapters = [{
"id": 860,
"firstName": "Superman",
"lastName": "Yoda"
}, {
"id": 870,
"firstName": "Foo",
"lastName": "Whateveryournameis"
}, {
"id": 590,
"firstName": "Toto",
"lastName": "Titi"
}, {
"id": 803,
"firstName": "Luke",
"lastName": "Kyle"
}];
}
我也尝试过使用dataresource
Plunker,但这里也很不幸。
它已经消耗了我很多时间。所以最后我决定听取大家的建议。任何帮助,将不胜感激。