作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 ng-repeat 输出数组:
<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;
}
在我的 this.helpers({
) 中。然而,这只输出 undefined
一次。我的印象是助手是 react 性的,那么为什么它只运行一次?
最佳答案
this.helpers({})
仅适用于响应式(Reactive)数据源,并且必须通过 Collection.find()
或 返回
(甚至是 mongoCursor
>Collection.findOne()Meteor.user()
)。 See docs 。
基元和函数必须在正常范围内声明,但我建议在助手中定义当前用户:
this.helpers({
currentUser() { return Meteor.user(); }
});
然后在按钮中使用ng-show="usr.data.driverId === currentUser._id"
。
关于javascript - 如何在 Angular/Meteor 中有条件地显示 ng-repeat 内的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34618427/
我是一名优秀的程序员,十分优秀!