Created
November 4, 2019 18:19
-
-
Save EsteveSegura/68b160256f6bb8a097673337b25df2ae to your computer and use it in GitHub Desktop.
admin.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Collecting data using jquery | |
function collectData(id) { | |
let dataCollected = { 'name': "", data: [] }//[] | |
$(`#${id}`).children('').each((i, el) => { | |
dataCollected.name = el.id.slice(0, -1); | |
if (el.tagName == "INPUT") { | |
dataCollected.data.push({ 'name': el.id, 'data': $(el).val() }) | |
} | |
}) | |
return dataCollected | |
} | |
//Send message via SocketIO | |
function emitMessage(message) { | |
console.log(message) | |
socket.emit('message', message); | |
} | |
//When we click a element with "clickable" class, send data. | |
$(".clickable").click((e) => { | |
console.log(e.target.id.slice(0, -1)) | |
let messageForEmite = collectData(e.target.id.slice(0, -1)) | |
emitMessage(messageForEmite) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment