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

164
Views
En JS, cómo pasar el parámetro de matriz a GAS y luego recuperar el resultado

En mi Hoja de Google tengo una lista de libros con sus detalles. El usuario inserta el título que está buscando, jQuery pasa el título a una función en GAS y luego devuelve las coincidencias (libros encontrados) al JS.

Aquí mi código.

HTML

 <form id="formD"> <input type="text" id="title" name="title" placeholder="Math"> <button id="submit">Search</button> </form>

JS

 $("#submit").click(function() { var data = []; data.push($("#title").val()); //title the user is looking for google.script.run.withSuccessHandler(onSuccess).find(data); }); function onSuccess(a) { alert(a); //example }

GAS

 function doGet() { return HtmlService.createTemplateFromFile('index') .evaluate() .addMetaTag('viewport', 'width=device-width, initial-scale=1'); } function find(data) { var sheet = SpreadsheetApp.openById("XXX").getSheetByName("XXX"); var range = sheet.getRange("A:G"); var values = range.getValues(); var result = []; var title = data[0]; for(i=0; i < values.length; i++){ if(values[i][0] != "") { if(values[i][2].includes(title)) result.push(values[i]); } } return result }

No sé cómo analizar y usar la matriz que paso a GAS. Cuando se hace clic en el botón "buscar", la página se vuelve a cargar y el valor se agrega a la URL.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Pruébalo de esta manera

 function find(data) { var sheet = SpreadsheetApp.openById("XXX").getSheetByName("XXX"); var range = sheet.getRange("A1:G" + sheet.getLastRow()); var values = range.getValues(); var result = []; var title = data; for (let i = 0; i < values.length; i++) { if (values[i][0] != "") { if (values[i][2].includes(title)) result.push(values[i]); } } return result; } function onSuccess(a) { alert(a.join('\n')); //example }

js:

No es necesario que los datos sean una matriz

 $("#submit").click(function() { var data = $("#title").val(); google.script.run.withSuccessHandler(onSuccess).find(data); });

comunicaciones de cliente a servidor

about 4 years ago · Juan Pablo Isaza Report

0

Aquí está la solución al problema de que al hacer clic en el botón se recarga la página.

 $("#sumbit").click(function(){ }

Este fragmento de código estaba fuera de $(document).ready(function(){}).

about 4 years ago · Juan Pablo Isaza Report
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!