如何在Angular/Meteor中有条件地显示ng repeat内的按钮



我有一个ng重复输出数组:

<div ng-repeat="usr in myPage.data.people track by $index">
  <button ng-click="leaveReviewUsr($index)" ng-show="isReviewable(usr)">
      review
  </button>
</div>

我希望能够根据另一个集合中是否已经有记录来有条件地显示按钮。查看一些文档,我似乎应该有一个助手来决定显示按钮,所以我尝试了

isReviewable(usr) {
  console.log(usr);
  if(this.data) {
    console.log(this.data.driverId + " / " + Meteor.userId());
    if(this.data.driverId == Meteor.userId()) {
      console.log(usr);
      return true;
    }
  }
  return false;
}

在我的CCD_ 1中。然而,这只输出undefined一次。我的印象是助手是被动的,那么为什么它只运行一次呢?

this.helpers({})仅用于响应式数据源,必须通过Collection.find()Collection.findOne()(甚至Meteor.user())返回mongoCursor。请参阅文档。

原语和函数必须在正常范围内声明,但我建议在助手中定义当前用户:

this.helpers({
    currentUser() { return Meteor.user(); }
});

然后在按钮中使用ng-show="usr.data.driverId === currentUser._id"

最新更新