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

131
Views
Destrucción de objeto en matriz en el próximo backend js

¿Cómo puedo resolver esto? Puse el parámetro req.query con una matriz, pero no puedo desestructurar ni usar elementos de mi matriz. Entro en mi backend API next.js solo [objeto Objeto] o indefinido. ¿Cómo puedo seleccionar lo que quiero?

 const fetchData = async (queryKey: any, manufacturer) => { const res = await fetch( `http://localhost:3000/api/data/get?&manufacturer=${manufacturers}` ); return await res.json(); }; const manufacturers = [ { name: 'Samsung', type: 'TV' }, { name: 'Nokia', type: 'Phone' }, ]; const { data, status } = useQuery( ['somekey', manufacturer], ({ queryKey }) => fetchData(queryKey, manufacturer) );

Y aquí está la siguiente API donde no puedo obtener valores de la consulta que obtengo solo [Objeto, Objeto] o indefinido,

este código funciona si solo se coloca en el front-end solo una matriz o cadena simple sin un objeto en los fabricantes de variables.

Pero, ¿cómo puedo obtener valores de [Objeto, objeto]? lo intento

 const { name, type } = req.query.manufacturer const { name, type } = req.query.manufacturer[0]

o seleccione solo un campo no funciona para = const some = req.query.manufacturer[0].name

 export const handler = async ( req: NextApiRequest, res: NextApiResponse<Data> ) => { const { name, type } = req.query.manufacturer; }; export default handler;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

¿Podría intentar const [{ name, type }] = req.query.manufacturer ? Parece ser lo que necesitas

editar

Además, es posible que desee probar en lugar de http://localhost:3000/api/data/get?&manufacturer=${manufacturers} => http://localhost:3000/api/data/get?&manufacturer=${encodeURIComponent(JSON.stringify(manufacturers))}

Probablemente será accesible con { name, type } = req.query.manufacturer luego

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!