首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当在条目对上使用中继器时,如何在Angular Smart-Table中应用筛选或排序规则

当在条目对上使用中继器时,如何在Angular Smart-Table中应用筛选或排序规则
EN

Stack Overflow用户
提问于 2015-10-09 04:21:17
回答 1查看 297关注 0票数 1

我有一个存储在FireBase中的数据结构,如下所示:

代码语言:javascript
复制
{ 'assets' : {
    'key1' : {
        'name':'application1',
        'deployed':'dev'
    },
    'key2' : {
        'name':'application2',
        'deployed':'prod'
    }

} }

我已经拉入了angular智能表,并具有以下表结构:

代码语言:javascript
复制
<table st-table='assets'>
  <thead>
    <th>Name</th>
    <th>Deployed</th>
  </thead>
  <tbody>
    <tr ng-repeat="(assetId, asset) in assets)">
        <td>{{asset.name}}</td>
        <td>{{asset.deployed}}</td>
    </tr>
  </tbody>
</table>

这一切似乎都很好用,但是如果我尝试使用

代码语言:javascript
复制
<th st-sort='name'>

或者如果我尝试使用以下命令添加搜索/过滤

代码语言:javascript
复制
<th><input st-search='name' type='search'/></th>

没有发生任何事情,我没有看到javascript失败或其他任何事情。

我怀疑这与中继器使用键/值对而不是普通对象有关。我试过使用'asset.name‘,但我得到了相同的结果,没有输出或错误,我不确定下一步该怎么做。

想法/想法?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2015-10-09 05:39:14

使用orderBy和filter可以得到您想要的结果

在控制器中,放置以下内容:

代码语言:javascript
复制
  $scope.sortType     = 'name'; // set the default sort type
  $scope.sortReverse  = false;  // set the default sort order
  $scope.searchFilter = '';     // set the default search/filter term

然后,在您的HTML中:

代码语言:javascript
复制
<input type="text" placeholder="Search" ng-model="searchFilter">

<table st-table='assets'>
  <thead>
    <th>
      <a href="#" ng-click="sortType = 'name'; sortReverse = !sortReverse">
        Name
        <span ng-show="sortType == 'name' && !sortReverse" class="caret-down"></span>
        <span ng-show="sortType == 'name' && sortReverse" class="caret-up"></span>
      </a>
    </th>
    <th>
      <a href="#" ng-click="sortType = 'deployed'; sortReverse = !sortReverse">
        Deployed
        <span ng-show="sortType == 'deployed' && !sortReverse" class="caret-down"></span>
        <span ng-show="sortType == 'deployed' && sortReverse" class="caret-up">
      </a>
    </th>
  </thead>
  <tbody>
    <tr ng-repeat="(assetId, asset) in assets | orderBy:sortType:sortReverse | filter:searchFilter">
      <td>{{asset.name}}</td>
      <td>{{asset.deployed}}</td>
    </tr>
  </tbody>
</table>

这里可能有一些小错误,因为我现在不在办公室,正在打电话。这应该会让你非常接近你正在寻找的东西。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33025259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档