繁体   English   中英

如果key为true,则返回false的true

[英]Return true of false if key is true

我想仅在当前用户是我使用checkGuest(event.$key)检查的来宾时显示事件

<md-card class="home-card" *ngFor="let event of events | async">
    <a *ngIf="checkGuest(event.$key)" [routerLink]="['event', event.$key]">
        <img class="event-home-img" src="https://lorempixel.com/300/300" />
        <p class="home-page-title">{{ event.name }}</p>
        <p class="home-page-venue">{{venueName}}</p>
    </a>
</md-card>

Firebase列表eventsGuestsLookup如下所示:

{
  "uid1" : {
    "-Ktm57w59Q_2c48r6ntx" : true,
  },
  "uid2" : {
    "-KtmbLqT0U005Ndelw3S" : true,
    "-KtmcLr44X0ho1NZP_h_" : true,
    "-KtmdP2BKzhwezxa-Lbl" : true,
    "-KtoGScCD7Zq4N3KkQQG" : true
  }
}

this.uiduid2eventKey-Ktm57w59Q_2c48r6ntx事件的关键是不是即使在uid2列表。 我希望this.hello返回false,但是正在为用户uid2显示数据库中的唯一事件……我在做什么错?

checkGuest(eventKey: string): Observable<Boolean> {

    const event = this.db.object(`eventsGuestsLookup/${this.uid}/${eventKey}`);

    return event.map(e => this.hello(e));
  }

  hello(e): Boolean {
    if (e) {
      return true;
    }
    return false;
  }

您是否正在对对象进行“映射”

如果要映射结果,则应使用db.list

角火力基地

您正在使用Boolean对象而不是boolean元。 这可能是问题吗?

编辑/更新(2017年9月13日):

我根本没有使用过angularfire ,但是从您的代码来看,它看起来像您的ngIf谓词函数checkGuest() ,正在返回FirebaseObjectObservable<boolean> ,无论它的boolean值如何,它truthytruthy (因为它被包装了)作为可观察到的)。

我想如果您将checkGuest()方法更改为此,

checkGuest(eventKey: string): boolean {
 return this.db.object(`eventsGuestsLookup/${this.uid}/${eventKey}`)
  .subscribe((e) => this.hello(e.$value));
}

它可能会起作用。 如果您仍在寻找答案,请尝试一下。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM