仅显示 post 如果用户在其中被标记且未完成|角火 |离子的

Only show post if user is tagged in it and its not completed| angularfire | ionic

嗨,我正在制作一个应用程序来跟踪我们的朋友组开支。

用户登录,应用创建账户(基于facebook账户)

在此之后,用户转到带有 "open payments" 的页面。我想根据当前用户是否被标记来过滤项目数组。

<div class="list card" ng-repeat="post in posts | openPayments:loggedInUserId">
              <div class="item">
                <h2>{{post.naam}}</h2>
              </div>

              <div class="item item-body">
                <p>
                  {{post.onderwerp}}
                </p>
                <h2>${{post.prijs}}</h2>
              </div>

              <div class="item" ng-repeat="post in post.users">
                <h2>{{post.naam}} | {{post.voltooid}}</h2>
              </div>

        </div>

json 数据

"posts" : {
    "post1" : {
      "naam" : "Event cards",
      "onderwerp" : "de kaarten voor het concert van nickelback",
      "prijs" : "60.-",
      "users" : {
        "1056952907701290" : {
          "naam" : "Facebook Name1",
          "voltooid" : false
        },
        "1230912128457790" : {
          "naam" : "Facebook name2",
          "voltooid" : true
        }
      }
    }

因此,如果我使用用户 ID 1056952907701290 登录,我只想查看标记了我的帖子,而不是 "voltooid"。

我的控制器

app.controller('LandingCtrl', function($scope, $state, credentials, $filter, currentUser, $firebaseObject, $firebaseArray) {

       //array
       var ref = new Firebase("https://bla.firebaseio.com/posts");
       $scope.posts = $firebaseArray(ref);
       console.log($scope.posts);
       $scope.newItem = function(){
          $state.go("app.newItem");
       }
       //username
       $scope.username = currentUser.facebook.displayName;
       $scope.loggedInUserId = currentUser.facebook.id;
       console.log($scope.username);
       console.log($scope.loggedInUserId);
})
app.filter("openPayments", function() {

  return function(input, username) {

    var returnArr = [];
    // Go over each post
    for(var i in input) {

      // Go over each user
      angular.forEach(input[i].users, function(value, key) {
        console.log("key " + key);
        console.log(input);
        console.log("username " + username);

        // If it's the user we're looking for and voltooid is true, add the item to the array 
        if(key == username && value.voltooid) {
          returnArr.push(input[i]);
        }

      });

    }

    return returnArr;

  }

});

我做了一些研究,但无法真正找到如何过滤子媒体资源。

angular.module('yourModule')

.filter("openPayments", function() {

  return function(input, userId) {

    var filteredArr = [];

    // Go over each post
    for(var i in input) {

      // Go over each user
      for(var j in input[i].users) {

        // If it's the user we're looking for and voltooid is true, add the item to the array 
        if(j == userId && input[i].users[j].voltooid) {
          filteredArr.push(input[i]);
        }

      }

    }

    return filteredArr;

  }

});

然后就可以这样使用了:

<div class="list card" ng-repeat="post in posts | openPayments:loggedInUserId">
...
</div>