我正在为 twilio-programmable-chat 使用 twilio javascript sdk。
我想对我的 channel 结果应用分页,但我无法弄明白。
这是我当前的代码。
this.chatClient.getUserChannelDescriptors().then(paginator => {
// All channels are fetched
})
我尝试传递一个类似于 getMessages(10)
工作方式的 pageSize
,但没有成功。
this.chatClient.getUserChannelDescriptors(10).then(paginator => {
// The result was same, it fetched all the channels instead of just 10
})
我正在寻找一个示例,说明如何在 channel 上进行分页。 谢谢。
最佳答案
我终于找到了一种方法。
它应该递归完成,因为我们通过调用 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);
}
}
这就是您将在每次通话中得到的信息。
关于javascript - 如何在 twilio-programmable-chat 的 channel 上进行分页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54685093/