Mun*_*eeb 1 javascript twilio reactjs twilio-programmable-chat
我正在使用 twilio javascript sdk 进行 twilio-programmable-chat。
我想对我的频道结果应用分页,但我无法弄清楚。
这是我当前的代码。
this.chatClient.getUserChannelDescriptors().then(paginator => {
// All channels are fetched
})
Run Code Online (Sandbox Code Playgroud)
我试图通过一个pageSize类似于 how getMessages(10)work 的方法,但是没有用。
this.chatClient.getUserChannelDescriptors(10).then(paginator => {
// The result was same, it fetched all the channels instead of just 10
})
Run Code Online (Sandbox Code Playgroud)
我正在寻找一个示例,说明如何在频道上完成分页。谢谢。
我终于找到了一种方法来做到这一点。
它应该递归完成,因为我们通过调用获取初始列表,getUserChannelDescriptors()然后可以通过调用获取其余记录nextPage();
async function processChannels(paginator) {
// Now, if hasNextPage is true
// call nextPage() to get the records instead of getUserChannelDescriptors()
if (paginator.hasNextPage) {
const nextPaginator = paginator.nextPage();
processChannels(nextPaginator);
} else {
console.log("END OF RECORDS");
}
}
async function getChannels() {
const paginator = await chatClient.getUserChannelDescriptors();
// Initiate the recursive function
if (paginator.items) {
await processChannels(paginator);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是您在每次通话中都会得到的信息。
| 归档时间: |
|
| 查看次数: |
1067 次 |
| 最近记录: |