【问题标题】:Dynamically change Pagination page size from angular scope value从角度范围值动态更改分页页面大小
【发布时间】:2016-08-13 04:41:26
【问题描述】:

我正在尝试允许用户更改要显示的表中的行数。该网络应用程序用于所有类型的设备,因此用户需要能够选择要显示的行数以最大限度地减少滚动。

这是javascript模型

$scope.pageSizes = [
  { size: 10},
  { size: 25, isSelected: true },
  { size: 50}
];

HTML 代码。这是我的页面大小选择器。

<li ng-repeat="pageSize in pageSizes">
  <a href="javascript:void(0)" ng-click="changePageSize(pageSize.size)"><span ng-class="{ orange: pageSize.isSelected }">{{pageSize.size}}</span></a>
</li>

和表格在同一个HTML文件中。

<table st-table="users" st-safe-src="safeUsers" class="table-striped argus-table">
  <thead>
    <tr>
      <th st-sort="id" class="sortable min-width">Id</th>
      <th st-sort="username" class="sortable">Username</th>
      <th st-sort="email" class="sortable">Email</th>
      <th class="table-action-header"></th>
      <th class="table-action-header"></th>
      <th class="table-action-header"></th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="user in users">
      <td>ID</td>
      <td>Username</td>
      <td>Email</td>
      <td>Option 1</td>
      <td>Option 2</td>
      <td>Option 3</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td class="text-center" st-pagination="" st-items-by-page="25" colspan="6"></td>
    </tr>
  </tfoot>
</table>

st-items-by-page="25" 是我认为我必须放置 Angular 代码的地方。

我已经尝试使用范围函数来查找新选择的对象

$scope.changePageSize = function (pageSize) {
  $scope.filter.pageSize = pageSize;

  _.find($scope.pageSizes, function (page) {
    if (page === pageSize) {
      $scope.selectedPageSize = page.size;
      page.isSelected = true;
    }
    else
      page.isSelected = false;
  });
};

又是页脚

<tfoot>
  <tr>
    <td class="text-center" st-pagination="" st-items-by-page="{{selectedPageSize}}" colspan="6"></td>
  </tr>
</tfoot>

但是这会导致错误

Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the expression [{{getSelectedPageSize}}] starting at [{getSelectedPageSize}}].

任何帮助将不胜感激。谢谢

【问题讨论】:

标签: javascript html angularjs pagination smart-table


【解决方案1】:

不要使用模板表示法 ({{scopeValue}}) 提供每页的项目,只需提供解析为 $scope 上的值的表达式

这个

st-items-by-page="{{selectedPageSize}}"

应该是这样的

st-items-by-page="selectedPageSize"

docs中有一个例子

【讨论】:

    猜你喜欢
    • 2017-06-21
    • 2017-08-05
    • 1970-01-01
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多