大佬教程收集整理的这篇文章主要介绍了javascript – Firebase:加入表格,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
post: { authorId: '123AA',title: 'first Post',body: 'yay' } author: { uid: '123AA',displayName: 'Richard' email: 'im@richard.com' }
我想使用作者姓名呈现帖子:
<div className="post"> <div className="title">{post.titlE}</div> <div className="body">{post.body}</div> <div className="author-name">{post.author.displayNamE}</div> //problem </div>
提取的帖子项目只包含作者的uid,但我需要作者的displayName.检索帖子时如何填充作者字段?这就是我现在要取的帖子:
const postsRef = firebase.database().ref('posts/') postsRef.on('value',(snapshot) => { this.setState({posts: snapshot.val()}) })
import { Component,OnInit } from '@angular/core'; import { AngularFire } from 'angularfire2'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; @Component({ SELEctor: 'app',templateUrl: ` <ul> <li *ngFor="let p of posts | async"> {{ p.title }} - {{ (p.authorName | asynC)?.displayName }} </li> </ul> ` }) export class InitComponent implements OnInit { posts: Observable<anY[]>; constructor(private af: AngularFirE) {} ngOnInit() { this.posts = this.af.database.list('/posts') .map(posts => { posts.map(p => { p.authorName = this.af.database.object('/authors/'+p.authorId); }); return posts; }); }
数据库结构如下:
/posts/postId/{authorId,title,body} /authors/authorId/{displayName,email}
希望这可以帮助
以上是大佬教程为你收集整理的javascript – Firebase:加入表格全部内容,希望文章能够帮你解决javascript – Firebase:加入表格所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。