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

140
Views
Cómo representar un objeto secundario a partir de un objeto principal en el menú desplegable de selección de materialUI

Estoy creando la aplicación ReactJS en la que quiero representar los objetos secundarios del objeto principal en el menú desplegable usando materialUI select. Traté de implementarlo iterando sobre el objeto usando la función map() pero no obtengo valor cuando hago clic en el menú desplegable.

Aquí está mi código fuente para crear el menú desplegable.

 import React from "react"; import { Select, MenuItem, FormControl, InputLabel } from "@material-ui/core"; import "./CamSelect.css" export default class CamSelect extends React.Component { constructor(props) { super(props); this.state = { currentLocation: localStorage.getItem("location"), data: [ { location: "abc", link: [ {name: "cam1", url: "https://...."}, {name: "cam2", url: "https://...."} ] }, { location: "xyz", link: [ {name: "cam1", url: "https://...."}, ] }, ], selected: '', }; } handleChange = (event) => { this.setState({ selected: event.target.value, name: event.target.name }); }; renderOptions() { return this.state.data.map((dt, i) => { if(this.state.currentLocation == dt.location){ dt.link.map(lnk => { console.log(lnk.name) return ( <MenuItem label="Select a camera" value={lnk.url} key={i} name={lnk.name} > {lnk.name} </MenuItem> ) }) } } ) }; render() { return ( <FormControl className="camera-select" style={{ minWidth: "100px"}}> <InputLabel id="demo-simple-select-label" style={{color:"white"}}>Cam</InputLabel> <Select labelId="demo-simple-select-label" id="demo-simple-select" className="camera-text-color" value={this.state.selected} onChange={this.handleChange} > {this.renderOptions()} </Select> </FormControl> ); } }

Mi expectativa es que cuando la ubicación actual sea igual a la clave de ubicación, es decir, "abc" , que está en el objeto de matriz, entonces quiero mostrar el valor de cam1, cam2 en el menú desplegable.

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

0

Cuando está iterando sobre dt.link.map , no devuelve el resultado, por lo que renderOptions tampoco devuelve nada => no se representa nada.

Deberías tener una devolución aquí:

 return dt.link.map(lnk => {

Esto devolverá un JSX.Element[][] , y desea un JSX.Element[] . Si solo habrá una ubicación coincidente, podría hacer this.state.data.find(dt => this.state.currentLocation == dt.location).map(...)

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!