Why are the callback functions in my nested functions not working?
P粉957661544
P粉957661544 2024-03-19 20:32:38
0
1
402

I'm using Socket.io's callback function, like this:

loadData(callback) {

var client = new SyncClient(this.socket, this.project);
this.client = client; //Data function from me

    client.on("connected", () => {
        this.values ​​= client.getData();
        callback(client);
    }
}

But when I call my function loadData, this error message appears in the console: Uncaught TypeError: callback is not a function.

I think callback() is trying to call it's parent which is a function created inside client.on instead of loadData( callback)? Or does the problem lie elsewhere?

Call my loadData() like this in my mounted:

mounted() {
    this.loadData(this.client)
}

P粉957661544
P粉957661544

reply all(1)
P粉645569197

Try using the data (res) received from the .find callback function and pass it to your callback function:

socket.on('getSettings', function (data, callback) {

    console.log('Settings broadcast.');

    lmsSettings.find({}, function (err, res) {
        callback(false, res);
    });
});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template