Typescript Nativescript:ListView不显示项目

Typescript Nativescript:ListView不显示项目,typescript,listview,asynchronous,nativescript,nativescript-angular,Typescript,Listview,Asynchronous,Nativescript,Nativescript Angular,我试图在ListView中显示聊天列表,但没有显示任何项目。我尝试查看Nativescript文档,设置是这样的,但没有显示任何内容。 我试过使用实时数据和虚拟数据。当使用实时数据时,我可以看到它的到来 以下是我的组件代码: XML: 打字稿: import { Component, OnInit, ViewChild, ElementRef, OnChanges, SimpleChanges, NgZone, ChangeDe

我试图在ListView中显示聊天列表,但没有显示任何项目。我尝试查看Nativescript文档,设置是这样的,但没有显示任何内容。 我试过使用实时数据和虚拟数据。当使用实时数据时,我可以看到它的到来

以下是我的组件代码:

XML:


打字稿:

import {
    Component,
    OnInit,
    ViewChild,
    ElementRef,
    OnChanges,
    SimpleChanges,
    NgZone,
    ChangeDetectionStrategy,
    AfterViewInit
} from '@angular/core';
import { Observable, pipe } from 'rxjs';
import { ListView } from 'tns-core-modules/ui/list-view';
import { TextField } from 'tns-core-modules/ui/text-field';
import { PageRoute, RouterExtensions } from 'nativescript-angular/router';
import { switchMap } from 'rxjs/operators';
import * as firebase from 'nativescript-plugin-firebase';
import { firestore } from 'nativescript-plugin-firebase';
import { IUser } from '~/app/_model/user';
import { IChatItem, EStatus, IMessage } from '../chat.component';
import { FirebaseService } from '~/app/shared/services/firebase.service';

@Component({
    selector: 'ns-chat-conversation',
    templateUrl: './chat-conversation.component.html',
    styleUrls: ['./chat-conversation.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ChatConversationComponent implements OnInit, OnChanges, AfterViewInit {

    public user: IUser = null;
    public chats$: Observable<IMessage[]> = null;
    public chatId: string = null;

    public processing: boolean = true;
    public list: ListView;
    public textfield: TextField;
    public chat: IChatItem = {
        user: {
            uid: '',
            name: '',
            email: '',
            userType: 0,
            institutionTitle: '',
            institutionId: null,
            fieldTitle: '',
            fieldId: null,
            level: '',
            rating: 0,
            startDate: new Date(),
            profilePictureSrc: null,
        },
        chatInfo: {
            subject: '',
            messages: [],
            status: EStatus.ACCEPTED,
            hoursLeft: 2,
            chatId: '',
        },
    };

    public chat$: Observable<IMessage[]> = null;
    public messages: IMessage[] = [];

    @ViewChild('list', { static: false }) lv: ElementRef;
    @ViewChild('textfield', { static: false }) tf: ElementRef;

    constructor(
        private _pageRoute: PageRoute,
        private ngZone: NgZone,
        private _firebaseService: FirebaseService
    ) {
        this._pageRoute.activatedRoute
            .pipe(switchMap((activatedRoute) => activatedRoute.params))
            .forEach((params) => {
                this.chatId = params.id;
            });

            firebase
                .getCurrentUser()
                .then((user) => {
                    const userDocument = firebase.firestore
                        .collection('users')
                        .doc(user.uid);

                    userDocument.get().then((doc) => {
                        this.user = {
                            uid: doc.data().uid,
                            name: doc.data().name,
                            email: doc.data().email,
                            userType: doc.data().userType,
                            institutionTitle: doc.data().institutionTitle,
                            institutionId: doc.data().institutionId,
                            fieldTitle: doc.data().fieldTitle,
                            fieldId: doc.data().fieldId,
                            level: doc.data().level,
                            rating: doc.data().rating,
                            startDate: doc.data().startDate,
                            profilePictureSrc: doc.data().profilePictureSrc,
                        };

                        this.chat$ = this._firebaseService.getChat$(
                            this.chatId,
                            this.user.uid
                        );

                        this.chats$ = this.chat$;

                        this.chat$.subscribe((dd) => {
                            this.messages = dd;
                            this.processing = false;
                        });

                    });
                })
                .catch((error) => console.log('Trouble in paradise: ' + error));

    }

    public ngOnInit(): void {}

    public ngOnChanges(simpleChanges: SimpleChanges): void {
        if ('chats$' in simpleChanges) {
            console.log('check it');
        }

}

导入{
组成部分,
奥尼特,
ViewChild,
ElementRef,
一旦改变,
SimpleChanges,
NgZone,
改变检测策略,
AfterViewInit
}从“@angular/core”开始;
从“rxjs”导入{observatable,pipe};
从“tns核心模块/ui/list view”导入{ListView};
从“tns核心模块/ui/text-field”导入{TextField};
从“nativescript/router”导入{PageRoute,RouterExtensions};
从“rxjs/operators”导入{switchMap};
从“nativescript插件firebase”导入*作为firebase;
从“nativescript插件firebase”导入{firestore};
从~/app/_model/user'导入{IUser};
从“../chat.component”导入{IChatItem,EStatus,IMessage};
从“~/app/shared/services/firebase.service”导入{FirebaseService};
@组成部分({
选择器:“ns聊天对话”,
templateUrl:'./chat conversation.component.html',
样式URL:['./chat conversation.component.scss'],
changeDetection:ChangeDetectionStrategy.OnPush,
})
导出类ChatConversationComponent实现OnInit、OnChanges和AfterViewInit{
公共用户:IUser=null;
公共聊天$:可观察=空;
public chatId:string=null;
公共处理:布尔值=true;
公共列表:ListView;
公共文本字段:文本字段;
公共聊天:iCatItem={
用户:{
uid:“”,
名称:“”,
电子邮件:“”,
用户类型:0,
机构名称:'',
institutionId:null,
字段名称:“”,
fieldId:null,
级别:“”,
评级:0,
开始日期:新日期(),
profilePictureSrc:null,
},
聊天信息:{
主题:'',
信息:[],
状态:EStatus.ACCEPTED,
左小时:2,
chatId:“”,
},
};
公共聊天$:可观察=空;
公共消息:IMessage[]=[];
@ViewChild('list',{static:false})lv:ElementRef;
@ViewChild('textfield',{static:false})tf:ElementRef;
建造师(
专用页面路由:页面路由,
私人ngZone:ngZone,
private\u firebaseService:firebaseService
) {
此.\u pageRoute.activatedRoute
.pipe(开关映射((activatedRoute)=>activatedRoute.params))
.forEach((参数)=>{
this.chatId=params.id;
});
火基
.getCurrentUser()
。然后((用户)=>{
const userDocument=firebase.firestore
.collection('用户')
.doc(user.uid);
userDocument.get()。然后((doc)=>{
此用户={
uid:doc.data().uid,
名称:doc.data().name,
电子邮件:doc.data().email,
userType:doc.data().userType,
institutionTitle:doc.data().institutionTitle,
institutionId:doc.data().institutionId,
fieldTitle:doc.data().fieldTitle,
fieldId:doc.data().fieldId,
级别:doc.data().level,
评级:doc.data().rating,
startDate:doc.data().startDate,
profilePictureSrc:doc.data().profilePictureSrc,
};
this.chat$=this.\u firebaseService.getChat$(
这个,查蒂,
此文件为.user.uid
);
this.chats$=this.chat$;
此.chat$.subscribe((dd)=>{
this.messages=dd;
此项处理=错误;
});
});
})
.catch((错误)=>console.log(‘天堂中的麻烦:’+error));
}
public ngOnInit():void{}
公共ngOnChanges(simpleChanges:simpleChanges):无效{
if('chats$'在simpleChanges中){
console.log('check it');
}
}
import {
    Component,
    OnInit,
    ViewChild,
    ElementRef,
    OnChanges,
    SimpleChanges,
    NgZone,
    ChangeDetectionStrategy,
    AfterViewInit
} from '@angular/core';
import { Observable, pipe } from 'rxjs';
import { ListView } from 'tns-core-modules/ui/list-view';
import { TextField } from 'tns-core-modules/ui/text-field';
import { PageRoute, RouterExtensions } from 'nativescript-angular/router';
import { switchMap } from 'rxjs/operators';
import * as firebase from 'nativescript-plugin-firebase';
import { firestore } from 'nativescript-plugin-firebase';
import { IUser } from '~/app/_model/user';
import { IChatItem, EStatus, IMessage } from '../chat.component';
import { FirebaseService } from '~/app/shared/services/firebase.service';

@Component({
    selector: 'ns-chat-conversation',
    templateUrl: './chat-conversation.component.html',
    styleUrls: ['./chat-conversation.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ChatConversationComponent implements OnInit, OnChanges, AfterViewInit {

    public user: IUser = null;
    public chats$: Observable<IMessage[]> = null;
    public chatId: string = null;

    public processing: boolean = true;
    public list: ListView;
    public textfield: TextField;
    public chat: IChatItem = {
        user: {
            uid: '',
            name: '',
            email: '',
            userType: 0,
            institutionTitle: '',
            institutionId: null,
            fieldTitle: '',
            fieldId: null,
            level: '',
            rating: 0,
            startDate: new Date(),
            profilePictureSrc: null,
        },
        chatInfo: {
            subject: '',
            messages: [],
            status: EStatus.ACCEPTED,
            hoursLeft: 2,
            chatId: '',
        },
    };

    public chat$: Observable<IMessage[]> = null;
    public messages: IMessage[] = [];

    @ViewChild('list', { static: false }) lv: ElementRef;
    @ViewChild('textfield', { static: false }) tf: ElementRef;

    constructor(
        private _pageRoute: PageRoute,
        private ngZone: NgZone,
        private _firebaseService: FirebaseService
    ) {
        this._pageRoute.activatedRoute
            .pipe(switchMap((activatedRoute) => activatedRoute.params))
            .forEach((params) => {
                this.chatId = params.id;
            });

            firebase
                .getCurrentUser()
                .then((user) => {
                    const userDocument = firebase.firestore
                        .collection('users')
                        .doc(user.uid);

                    userDocument.get().then((doc) => {
                        this.user = {
                            uid: doc.data().uid,
                            name: doc.data().name,
                            email: doc.data().email,
                            userType: doc.data().userType,
                            institutionTitle: doc.data().institutionTitle,
                            institutionId: doc.data().institutionId,
                            fieldTitle: doc.data().fieldTitle,
                            fieldId: doc.data().fieldId,
                            level: doc.data().level,
                            rating: doc.data().rating,
                            startDate: doc.data().startDate,
                            profilePictureSrc: doc.data().profilePictureSrc,
                        };

                        this.chat$ = this._firebaseService.getChat$(
                            this.chatId,
                            this.user.uid
                        );

                        this.chats$ = this.chat$;

                        this.chat$.subscribe((dd) => {
                            this.messages = dd;
                            this.processing = false;
                        });

                    });
                })
                .catch((error) => console.log('Trouble in paradise: ' + error));

    }

    public ngOnInit(): void {}

    public ngOnChanges(simpleChanges: SimpleChanges): void {
        if ('chats$' in simpleChanges) {
            console.log('check it');
        }

}