【问题标题】:Smart-Table "st-sort" not working智能表“st-sort”不起作用
【发布时间】:2015-03-30 10:03:57
【问题描述】:

我正在使用 Angular v1.3.15。我通过点击一个 api 并将其通过范围传递给智能表来获取数据,就像这样

这是控制台上看到的“scope.rowCollection”的数据格式

数据填充得很好,但是当我尝试单击表头并使用 st-sort 方法对其进行排序时,表值显然会变为空白,而不是对列进行排序。这是我的 html sn-p 的视图

你能告诉我我到底做错了什么吗?当我使用我自己的数据收集集(不是硬编码)时,整个表的值就乱套了。 我感觉这与我在角端使用的变量名有关。 非常感谢任何帮助....谢谢

【问题讨论】:

    标签: angularjs smart-table


    【解决方案1】:

    关注您的评论 Nikhil。像这样使用 st-safe-src

    HTML

    <table st-table="displayedCollection" st-safe-src="rowCollection">
          <thead>
            <tr>
              <th st-sort="firstName">First Name</th>
              <th st-sort="lastName">Last Name</th>
            </tr>
          </thead>
          <tbody>
            <tr ng-repeat="row in displayedCollection">
              <td>{{row.firstName}}</td>
              <td>{{row.lastName}}</td>
            </tr>
          </tbody>
    </table>
    

    JS

    app.controller('Ctrl', function($scope, service) {
        $scope.displayedCollection = [];
    
        service.all.then(function(list) {
            $scope.rowCollection = list;
            $scope.displayedCollection = list;
        });
    });
    

    就是这样。

    【讨论】:

    【解决方案2】:

    如果您异步引入数据(从远程数据库、restful 端点、ajax 调用等),您必须使用 stSafeSrc 属性。您必须为基本集合和安全集合使用单独的集合,否则您可能会陷入无限循环。

    因为我从 restful 服务获取数据 st-table="displayedCollection" st-safe-src="rowCollection" 解决我的问题

    【讨论】:

    • 很高兴有一些解释,因为最佳答案没有任何解释!
    【解决方案3】:

    我认为它正在尝试以您编码的方式对 row.name 进行排序。试试下面的方法看看是否有效:

         st-sort="employee.name"
    

    【讨论】:

    • 嘿凯.. 谢谢你的建议。我也试过了,但似乎没有用。显然我相信我的数据是异步加载的,根据智能表文档here,我应该使用st-safe-src 属性
    猜你喜欢
    • 2016-02-14
    • 1970-01-01
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    • 1970-01-01
    • 2017-07-03
    • 2017-05-10
    • 2016-10-08
    相关资源
    最近更新 更多