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粉6455691972024-03-20 16:17:44
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); }); });