如何在 node.js 中获取箭头函数的值
how to get the value of an arrow function in node.js
我想获取变量“final”的值,以便能够通过套接字发送到前端
我的代码
const admin = database.collection("admin").onSnapshot(documento =>{
const final = documento.docs.map((doc) =>({id: doc.id, ...doc.data()}))
return final
})
const alerts = admin()
console.log(alerts);
//sockets
io.on('connection', function (socket) {
console.log('Alguien se ha conectado con Sockets');
socket.emit('alerts', alerts);
socket.on('new-alert', function (data) {
alerts.push(data);
io.sockets.emit('alerts', alerts);
});
});
//sockets
我会在调用 onSnapshot
时放置必要的逻辑。
const admin = database.collection("admin").onSnapshot(documento =>{
const final = documento.docs.map((doc) =>({id: doc.id, ...doc.data()}))
// Code that uses final here
})
是的,我的最终密码是
//sockets
io.on('connection', function (socket) {
console.log('Alguien se ha conectado con Sockets');
const admin = database.collection("admin").onSnapshot(documento =>{
const alerts = documento.docs.map((doc) =>({id: doc.id, ...doc.data()}))
socket.emit('alerts', alerts);
socket.on('new-alert', function (data) {
alerts.push(data);
io.sockets.emit('alerts', alerts);
});
})
});
//sockets
我想获取变量“final”的值,以便能够通过套接字发送到前端
我的代码
const admin = database.collection("admin").onSnapshot(documento =>{
const final = documento.docs.map((doc) =>({id: doc.id, ...doc.data()}))
return final
})
const alerts = admin()
console.log(alerts);
//sockets
io.on('connection', function (socket) {
console.log('Alguien se ha conectado con Sockets');
socket.emit('alerts', alerts);
socket.on('new-alert', function (data) {
alerts.push(data);
io.sockets.emit('alerts', alerts);
});
});
//sockets
我会在调用 onSnapshot
时放置必要的逻辑。
const admin = database.collection("admin").onSnapshot(documento =>{
const final = documento.docs.map((doc) =>({id: doc.id, ...doc.data()}))
// Code that uses final here
})
是的,我的最终密码是
//sockets
io.on('connection', function (socket) {
console.log('Alguien se ha conectado con Sockets');
const admin = database.collection("admin").onSnapshot(documento =>{
const alerts = documento.docs.map((doc) =>({id: doc.id, ...doc.data()}))
socket.emit('alerts', alerts);
socket.on('new-alert', function (data) {
alerts.push(data);
io.sockets.emit('alerts', alerts);
});
})
});
//sockets