未能将此挑战与文档协调:/希望有人能向我指出为什么当这个lwc呈现(成功)并通过其empApi订阅接收一个事件时,它抛出一个'handleGoNext未定义‘运行时错误。我知道这个函数是不可见的,但是我不能构造这样的东西,这样就可以成功地进行函数调用。调用this.handleGoNext()也不起作用。任何指点都将不胜感激!
handleGoNext(){
// *** this is the logic Im hoping to call ***
};
// Initializes the component
connectedCallback() {
if(this.subscription = {}){
// Callback invoked whenever a new event message is received
const messageCallback = function (response) {
handleGoNext(); // *** THIS IS THE CALL THAT BREAKS THINGS ***
};
// Invoke subscribe method of empApi. Pass reference to messageCallback
subscribe(this.channelName, -1, messageCallback).then((response) => {
// Response contains the subscription information on subscribe call
console.log(
'Subscription request sent to: ',
JSON.stringify(response.channel)
);
this.subscription = response;
});
}
}发布于 2022-11-29 07:05:59
当你做subscribe(this.channelName, -1, this.handleGoNext)时会发生什么
这是我在复活节前后的功能,最近没有检查它是否仍然有效。
isSubscribed = false;
subscription = {};
replayId;
@track data = [];
subscribe(id) {
const handleMessage = (response) => {
let val = Object.assign({}, response.data.event, response.data.payload);
this.replayId = Math.max(this.replayId ?? 0, val.replayId);
/* do not use this.data.push(val);
it doesn't play well with datatable. Use the spread operator or JSON.parse/JSON.stringify trick.
Plus we want new rows to be added on top of the list.`
*/
this.data = [val, ...this.data];
};
subscribe(this.channel, id, handleMessage).then((response) => {
this.subscription = response;
this.isSubscribed = true;
});
}https://stackoverflow.com/questions/74609593
复制相似问题