[英]can't load an array to ngTable
I tried to write a small and simple ngTable demo, but got a problem: 我试图编写一个小而简单的ngTable演示,但遇到了一个问题:
When I try to put an array to ngTable, the browser shows only the head line of the table, but not data. 当我尝试将数组放入ngTable时,浏览器仅显示表的标题行,而不显示数据。 the result is in screenshot: 结果在屏幕截图中:
All the code are in plunker 所有的代码都在punker中
Here is the "data": 这是“数据”:
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 }];
and here is the way i created a ngTable 这是我创建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); }
and here is part of the html: 这是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>
Your error is you call createTable
function before you set initpageSize
so initParams.counts
is undefined 您的错误是您在设置initpageSize
之前调用createTable
函数,因此initParams.counts
是未定义的
You have to put this lines before you call to createTable
您必须在致电createTable
之前放这行
var initpageSize = Number(localStorage.getItem('page_size') || 20);
vm.pageSize = initpageSize;
vm.pageSizes = [10,20,30,50,100];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.