用于Javascript/MongoDB中的循环条件

For loop conditions in Javascript/MongoDB

本文关键字:循环 条件 MongoDB Javascript 用于      更新时间:2023-10-30

我正在尝试显示表的内容,并使用使其正常工作

<div class="mrb-notification alert alert-success alert-dismissable" ng-repeat="thing in awesomeThings">
<button type="button" class="close" ng-click="hideThing(thing)">&times;          </button>
{{thing.name}} <font color="gray"><p class="text-right">{{thing.date | date : 'medium'}}</p></font>
</div>

这显示了"awesomeThings"中的所有"thing",用户可以点击带有"hideThing(thing)"功能的关闭按钮,该按钮将当前用户的ID添加到awesomeThings中的一个数组中。该数组包含选择隐藏"thing)的用户列表。

我现在的问题是,如果当前用户不在数组中,我如何只显示"thing"。用户id变量名为"getCurrentUser.id",数组名为"hideFromUser"。

在我的脑海中,我正试图做一些类似的事情

PSEUDOCODE
//for thing in awesomethings
 //show thing if 
  //getCurrentUser.id is not in thing.hideFromUser

有没有一种方法可以使用ng if和ng repeat来实现这一点,或者我可以在JS中实现它?

我会在$scope上实现一个类似isShown(hiddenUserArray)的js方法,然后用ng-if="isShown"(thing.hideFromUSer)"调用这个fn。

我们将使用lodash-lib(例如_.contains)来实现fn。