如何知道前端完成渲染的时间?
我的意思是,你的后端有一些东西 你的观点是什么。
我怎么知道什么时候结束?我想知道因为我需要在完成时向下滚动,目前它在呈现之前滚动。
这是解决问题的一些代码: https://gist.github.com/mtnoronha/e78eba6b610b71f1e72424ed21722be1
谢谢
答案 0 :(得分:0)
创建一个新的承诺,以便在完成加载消息后进行处理,因此您需要滚动到底部,在您的情况下使用它如下:
您的.TS文件
appendRows(newData){
if(!newData || newData.length == 0)
return;
this.myNewPromise().then(res =>{
if(res){
this.content.scrollToBottom(0);
}
})
}
myNewPromise = (): Promise<boolean> =>{
return new Promise<boolean>(res){
if(this.messages){
let newArray = this.messages.concat(newData);
this.messages = newArray;
res(true);
}else{
this.messages = newData;
res(false);
}
}
}
所以scrollToBottom
只会在myNewPromise
完成时触发。在你的承诺中你解决它并返回一个布尔值,所以如果有新消息,你可以调用scrollToBottom
。
如果您需要以任一方式调用它,只需在res
中传递true,或在if (res)
返回时删除myNewPromise
。
希望它有所帮助。