0
如何知道前端完成渲染的時間?離子v2 - 如何知道前端完成渲染?
我的意思是,你的後端有一些東西,並且在你的視圖上有一個ngFor。
如何知道何時完成?我想知道,因爲我需要在完成時向下滾動,並且當前它在呈現之前滾動。
下面是一些代碼在於向世人證明問題: https://gist.github.com/mtnoronha/e78eba6b610b71f1e72424ed21722be1
謝謝
如何知道前端完成渲染的時間?離子v2 - 如何知道前端完成渲染?
我的意思是,你的後端有一些東西,並且在你的視圖上有一個ngFor。
如何知道何時完成?我想知道,因爲我需要在完成時向下滾動,並且當前它在呈現之前滾動。
下面是一些代碼在於向世人證明問題: https://gist.github.com/mtnoronha/e78eba6b610b71f1e72424ed21722be1
謝謝
創建一個新的承諾來處理時,它已經完成加載信息,所以你需要滾動到底,你的情況使用像這樣:
您.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或在myNewPromise
的返回中刪除if (res)
。
希望它有幫助。
嗨,我的朋友,非常感謝你的回答。你看,問題不在Javascript方面。問題在於Angular使用ngFor來創建基於更新的「messages」屬性的視圖。所以當我們在JS端調用scrollToBottom()時,Angular沒有完成構建視圖。 –
即使,我試過你的解決方案只是爲了確保,結果是一樣的:( –
你脫離ionViewDidEnter?它也調用scrollToBottom –