我尝试编写一个简单的小型ngTable演示,但遇到了一个问题:
当我尝试将数组放到ngTable时,浏览器只显示表的头行,但不显示数据。结果在截图中:
所有代码都在plunker
这是“数据”:
var books = [
{
"name": "Html from start to give up",
"price": 2,
"comment": "An awesome book to be a pillow",
"available": true
},
{
"name": "AngularJS from start to give up",
"price": 2,
"comment": "Too hard to be a pillow",
"available": false
}];
这是我创建ngTable的方式
vm.bookTable = createTable(books);
var initpageSize = Number(localStorage.getItem('page_size') || 20);
vm.pageSize = initpageSize;
vm.pageSizes = [10,20,30,50,100];
function createTable(data){
var initParams = {
sorting: {name: "asc"},
count: vm.pageSize
};
var initSettings = {
counts: [],
paginationMaxBlocks: 13,
paginationMinBlocks: 2,
dataset: data
};
return new NgTableParams(initParams, initSettings);
}
这里是html的一部分:
<body ng-controller="myController as vm">
<div>
<table ng-table= "vm.bookTable"
class = "table"
show-filter="true">
<tr ng-repeat="row in $data">
<td title = "'name'" filter="{name: 'text'}" sortable="'name'">
{{row.name}}
</td>
<td title = "'price'" filter="{price: 'number'}" sortable="'price'">
{{row.price}}
</td>
<td title = "'comment'" filter="{comment: 'number'}" sortable="'comment'">
{{row.count}}
</td>
</tr>
</table>
</div>
<p>Hello {{vm.name}}!</p>
</body>
答案 0 :(得分:1)
在设置createTable
之前,您的错误是调用initpageSize
函数
所以initParams.counts
未定义
在致电createTable
var initpageSize = Number(localStorage.getItem('page_size') || 20);
vm.pageSize = initpageSize;
vm.pageSizes = [10,20,30,50,100];
Here你有一名工作人员。