【发布时间】:2016-06-30 00:47:09
【问题描述】:
我正在创建一个 Angular 函数,我想抓取所有类别与单击的按钮匹配的博客文章,我的 Firebase 中有 3 个不同的字段,标题为 category1、category2 和 category3。例如,当用户单击时事通讯时,我想查看具有类别时事通讯的所有帖子,无论它存储在类别 1、类别 2 还是类别 3 中。我以为我可以concat()them。但它不起作用。这是我正在尝试的功能。
$scope.sortByNewsletter = function() {
var postsNumNews1 = $firebaseArray(ref.child('pPosts').orderByChild("category1").equalTo("Newsletters"));
var postsNumNews2 = $firebaseArray(ref.child('pPosts').orderByChild("category2").equalTo("Newsletters"));
var postsNumNews3 = $firebaseArray(ref.child('pPosts').orderByChild("category3").equalTo("Newsletters"));
console.log(postsNumNews1);
console.log(postsNumNews2);
console.log(postsNumNews3);
var $scope.postsNum = postsNumNews1.concat(postsNumNews2,postsNumNews3);
console.log($scope.postsNum);
}
然后我在 postNum 上重复 ng-repeating 以将它们显示到这样的页面。
<div class="blog-item" dir-paginate="post in postsNum | orderBy: 'postedDate': true | filter:searchPosts | itemsPerPage: 1">
<img class="img-responsive img-rounded" src="{{ post.imageOne }}" width="100%" alt="" />
<div class="blog-content">
<h3><strong>{{ post.title }}</strong></h3>
<h4><strong>{{ post.subTitle }}</strong></h4>
<div class="entry-meta">
<span><i class="fa fa-user"></i> {{ post.postedBy }}</span>
<span><i class="fa fa-folder"></i> {{ post.category1 }} {{ post.category2 }} {{ post.category3 }}</span>
<span><i class="fa fa-calendar"></i> {{ post.datePosted }}</span>
</div>
<br>
<p>{{ post.paragraph1 }}</p>
<p>{{ post.paragraph2 }}</p>
<p>{{ post.paragraph3 }}</p>
</div>
</div>
我还认为我可以将多个“类别”传递给我的 orderByChild(),但这也不起作用。
【问题讨论】:
标签: javascript angularjs firebase angularfire firebase-realtime-database