gpt4 book ai didi

javascript - 无法将数组加载到 ngTable

转载 作者:行者123 更新时间:2023-12-03 06:38:09 28 4
gpt4 key购买 nike

我尝试编写一个小而简单的 ngTable 演示,但遇到了问题:

当我尝试将数组放入 ngTable 时,浏览器仅显示表的标题行,而不显示数据。结果如截图所示:

enter image description here

所有代码都在 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>

最佳答案

您的错误是您在设置 initpageSize 之前调用了 createTable 函数所以 initParams.counts 未定义

您必须在调用 createTable 之前放置此行

  var initpageSize = Number(localStorage.getItem('page_size') || 20);
vm.pageSize = initpageSize;
vm.pageSizes = [10,20,30,50,100];

Here你有一个工作的笨蛋。

关于javascript - 无法将数组加载到 ngTable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38094991/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com