angularfire2:键入&#39; Observable <any []>&#39;不能分配给&#39; FirebaseListObservable <any>&#39;

时间:2016-12-12 05:50:34

标签: observable angularfire2

你好我在angularfire2新。我试图根据$ key值将对象连接到一个数组(列表)。

我当前的代码如下:

console.log("Create Relationship Person 2 Person Observable");
        const relationshipP2Ps$: FirebaseListObservable<any>  = af.database.list('/relationshipP2P') // Primary list
            .map(items => {
                // `items` is an array of all items at the moment
                for (let item of items) {
                    // Find each corresponding associated object and store it as a FibrebaseObjectObservable
                    const i: FirebaseObjectObservable<any> = af.database.object('/person/' + item.person1, { preserveSnapshot: true })
                    i.subscribe(snapshot1 => {
                        console.log(snapshot1.key)
                        item.person1FirstnameEng = snapshot1.val().firstnameEng;
                        item.person1LastnameEng = snapshot1.val().lastnameEng;
                        item.person1FirstnameZhs = snapshot1.val().firstnameZhs;
                        item.person1LastnameZhs = snapshot1.val().lastnameZhs;
                    });
                    const j:FirebaseObjectObservable<any> = af.database.object('/person/' + item.person2, { preserveSnapshot: true })
                    j.subscribe(snapshot2 => {
                        console.log(snapshot2.key)
                        item.person2FirstnameEng = snapshot2.val().firstnameEng;
                        item.person2LastnameEng = snapshot2.val().lastnameEng;
                        item.person2FirstnameZhs = snapshot2.val().firstnameZhs;
                        item.person2LastnameZhs = snapshot2.val().lastnameZhs;
                    });
                    const k :FirebaseObjectObservable<any> = af.database.object('/relationshipCategory/' + item.category, { preserveSnapshot: true })
                    k.subscribe(snapshot3 => {
                        console.log(snapshot3.key)
                        item.categoryNameEng = snapshot3.val().nameEng;
                        item.categoryNameZhs = snapshot3.val().nameZhs;
                    });

                    const l :FirebaseObjectObservable<any> = af.database.object('/relationship/' + item.relationship, { preserveSnapshot: true })
                    l.subscribe(snapshot4 => {
                        console.log(snapshot4.key)
                        item.relationshipNameEng = snapshot4.val().nameEng;
                        item.relationshipNameZhs = snapshot4.val().nameZhs;
                    });
                }

                return items;
            });
        relationshipP2Ps$.subscribe(relationshipP2Ps => this.relationshipP2Ps=relationshipP2Ps);

现在这一切都很好但是当它运行时我得到以下错误:

/src/app/relationship-p2p/relationship-p2p.service.ts:2:15 
    Type 'Observable<any[]>' is not assignable to type 'FirebaseListObservable<any>'.   Property '$ref' is missing in type 'Observable<any[]>'.

有关如何重写此内容的任何想法导致无错误?

0 个答案:

没有答案