Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
Enviar una grilla como json

Soy relativamente nuevo en el mundo de JavaScript. Creo una cuadrícula en la que puedo seleccionar cualquier celda. Ahora me gustaría enviar todas las celdas como binarias con un documento Json al backend. Para ello, una celda no seleccionada debe tener un 0 y una seleccionada debe tener un 1. Me oriento en el Juego de la Vida de Conway. He estado en esto durante 2 días y no sé cuál es la mejor manera de implementarlo. ¿Alguien tiene alguna idea?

Aquí está mi código para crear la grilla.

 var rows = 10; var cols = 10; var grid = new Array(rows); var nextGrid = new Array(rows); var startButton = document.getElementById('start'); startButton.addEventListener('click', event => { initialize() }) function initializeGrids() { for (var i = 0; i < rows; i++) { grid[i] = new Array(cols); nextGrid[i] = new Array(cols); } } function copyAndResetGrid() { for (var i = 0; i < rows; i++) { for (var j = 0; j < cols; j++) { grid[i][j] = nextGrid[i][j]; } } } // Initialize function initialize() { createTable(); initializeGrids(); } // Lay out the board function createTable() { var gridContainer = document.getElementById('gridContainer'); if (!gridContainer) { // Throw error console.error("Problem: No div for the drid table!"); } var table = document.createElement("table"); for (var i = 0; i < rows; i++) { var tr = document.createElement("tr"); for (var j = 0; j < cols; j++) { var cell = document.createElement("td"); cell.setAttribute("id", i + "_" + j); cell.setAttribute("class", "dead"); cell.onclick = cellClickHandler; tr.appendChild(cell); } table.appendChild(tr); } gridContainer.appendChild(table); } function cellClickHandler() { var rowcol = this.id.split("_"); var row = rowcol[0]; var col = rowcol[1]; var classes = this.getAttribute("class"); if(classes.indexOf("live") > -1) { this.setAttribute("class", "dead"); grid[row][col] = 0; } else { this.setAttribute("class", "live"); grid[row][col] = 1; } }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!