首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ng中筛选-单击Button重复

在ng中筛选-单击Button重复
EN

Stack Overflow用户
提问于 2016-02-13 16:32:40
回答 1查看 1.4K关注 0票数 0

我有一个正在进入$scope.notifications的Json。

代码语言:javascript
复制
**Json**
0:{ 
    $$hashKey: "object:31"
    action: "wrote a comment"
    creationDate: "2015-11-23 13:48:55.0"
    post: Object
    seen: true
    user: Object
   }

这个Json有一个键:可以是真的,也可以是假的。我必须在ng-重复其键上过滤掉那些对象:单击按钮is= false,未读通知.

然后再次清除单击“所有通知”按钮上的筛选器。

代码语言:javascript
复制
<div class="col-xs-12 col-sm-6 col-md-8">
    <ul class="notifications-action-menu text-center">
        <li>
            <button type="button" class="btn btn-link btnUnreadFilter active" data-filter="all" id="btnShowAll">All Notifications</button>
         </li>
         <li>
             <button type="button" class="btn btn-link btnUnreadFilter" data-filter="unread" id="btnShowOnlyUnread" ng-click="actions.unreadNotifications()">Unread Notifications</button>
         </li>
      <ul></ul>
      </ul>
</div>
<div class="col-xs-12">
<div id="notificationsListWrapper" ng-repeat="notification in notifications" ng-hide="{{notification.seen == seen}}">
    <div class="notification-item" ng-class="{'read' : notification.seen == true}">
        <div class=" no-click-bind mark-as-read-btn">
            <button type="button" class="no-click-bind" data-toggle="tooltip" data-placement="top" data-original-title="Mark as read"  ng-click="actions.redirectToPost(notification.post.uuid, $index)">
            <i class="fa fa-check"></i>
            </button>
         </div>
        <div class="notification-body">
            <div class="notification-details">
                <a href="" class="doc-profile-img"><img class="" alt="{{notification.user.authorName}}" ng-src="{{(notification.user.thumbnailUrl) ? notification.user.thumbnailUrl :'/assets/images/avatars/avatar_100x100.png'}}">
                </a>
                <a>{{notification.user.authorName}}</a><span class="notification-action"> {{notification.action}}</span>
                <a href="/news/abcd" class="notification-url no-click-bind">{{notification.post.title}}
               </a>
               <div class="notification-meta"><i class="fa notification-type-icon fa-calendar"></i> <small class="notification-datetime text-muted" title="Thursday, January 21, 2016 at 5:26 pm">Jan 21 2016</small>
              </div>
              <div class="notification-actions"></div>
          </div>
      </div>
      <div ng-if="notification.post.featuredAttachmentUrl != '' " class="notification-url-img"><img alt="" ng-src="{{notification.post.featuredAttachmentUrl}}"></div>
     </div>
</div>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-13 17:08:37

试一试如下:

代码语言:javascript
复制
ng-repeat="notification in notifications | filter:seenFilter"

其中,控制器将seenFilter设置为{ set : true }、{set:false}或true。示例:

代码语言:javascript
复制
$scope.actions.unreadNotifications = function(){
  $scope.seenFilter = {seen:false}
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35382366

复制
相关文章

相似问题

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