首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >带有筛选和排序的Angular customer指令

带有筛选和排序的Angular customer指令
EN

Stack Overflow用户
提问于 2017-08-26 14:08:48
回答 2查看 57关注 0票数 0

我需要通过ng- userType对json对象进行排序。现在我可以检索和显示数据了,问题是我需要在下面的列表中排序和显示两个不同的表;一个用于结婚,另一个用于单身。

当我使用ng-repeat,并且需要在两个表中显示时,如何对结婚/单身进行排序。如有任何建议/帮助,我们将不胜感激。

代码语言:javascript
运行
复制
.controller('userInfo', ['$scope', 'userService', function ($scope, userService) {
      userService.getuserList().then(function (users) {
        users = {
                "personalInfo": {
                    "firstName": "Richardoo",
                    "lastName": "Gil",
                    "maritalStatus": "Married",                    
                    "percentage": "50"
        },"personalInfo": {
                    "firstName": "Richardoo",
                    "lastName": "Gil",
                    "maritalStatus": "Single",                    
                    "percentage": "50"
        },
        "personalInfo": {
                    "firstName": "Richardoo",
                    "lastName": "Gil",
                    "maritalStatus": "Married",                    
                    "percentage": "50"
        }}

        $scope.users = users;
      });
    }])

.directive('userDetails', function () {
      return {
        restrict: 'E',
        scope: {
          users: '='
        },
        controller: function ($scope) {
          $scope.showEdit = function () {
            $scope.isEdit = true;
          }
        },
        template: `<div class="table-responsive">
      <table class="table">
          <thead>
              <tr>
                  <th>Name</th>
                  <th>Relation</th>
                  <th>Percentage</th>
                  <th></th>
              </tr>
          </thead>
          <tbody>
              <tr data-ng-repeat="user in users">
                  <td>{{user.personalInfo.firstName}} {{user.personalInfo.lastName}}</td>
                  <td>{{user.userRelations.relationshipType}}</td>
                  <td><span ng-if="!isEdit">{{user.personalInfo.percent}}</span><input type="text"
                          ng-if="isEdit" ng-model="user.personalInfo.percent" class="form-control"></td>
                  <td><a ng-click="showEdit()" href="#">Update</a></td>
              </tr>
          </tbody>
          <tfoot>
              <tr>
                  <td colspan="2">Total Percentage</td>
                  <td>100%</td>
                  <td><a ng-if="!isEdit" ng-click="showEdit()" href="#">Update</a><a ng-if="isEdit" ng-click="showEdit()" href="#">Save Percentage</a></td>
              </tr>
          </tfoot>
      </table>
  </div>`
      };
    })

    <div class="container">
    <div class="row">
        <div class="col-md-9">
            <h1>Update User Information</h1>
            <div data-ng-controller="user">
                <div data-ng-controller="userInfo">
                    <user-details user="users"></user-details>
                </div>
            </div>
        </div>
    </div>
</div>
EN

Stack Overflow用户

发布于 2017-08-26 15:13:35

代码语言:javascript
运行
复制
<tr data-ng-repeat="user in users | filter:{maritalStatus:userfilter}"></tr>

$scope.sortType = 'x.user‘

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

https://stackoverflow.com/questions/45892458

复制
相关文章

相似问题

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