智能表"st-sort"不工作 [英] Smart-Table "st-sort" not working

查看:93
本文介绍了智能表"st-sort"不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用角度v1.3.15.我通过点击一个api并将其通过范围传递到智能表来获取数据

I'm using angular v1.3.15. I'm fetching data by hitting an api and passing it through the scope to the smart table like so

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

Here is the data format of the 'scope.rowCollection' as seen on the console

数据可以很好地填充,但是当我尝试单击表头并使用st-sort方法对其进行排序时,表值显然变为空白而不对列进行排序.这是我的html代码段的视图

Data populates fine but When i'm trying to click on the table-header and sort it using st-sort method, the table values go blank clearly not sorting the column. Here is a view of my html snippet

能告诉我我到底在做什么错.当我使用自己的数据收集集(不进行硬编码)的时候,整个表的值就一团糟了. 我有一种感觉与我在角端使用的变量名有关. 非常感谢您的帮助....谢谢

Can you please tell me what exactly am i doing wrong. The moment i use my own data collection set(NOT hard coded) the whole table values go haywire. I have a feeling its something to do with the variable names that i'm using on the angular end. Any help is much appreciated....Thanks

推荐答案

Nikhil发表您的评论.像这样使用 st-safe-src :

Following your comment Nikhil. Use st-safe-src like so:

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;
    });
});

就是这样.

这篇关于智能表"st-sort"不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆