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

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

javascript - 无法将数组加载到ngTable-LMLPHP

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

最佳答案

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

致电createTable之前,必须先放置此行

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


Here您有一个正在工作的unk子。

10-06 04:28