简体   繁体   English

在JSX中的嵌套映射函数内部反映JS打印数据

[英]React JS printing data inside a nested map function in JSX

I am trying to print data inside a nested map function. 我试图在嵌套的地图函数中打印数据。 For some reason it does not print anything. 由于某种原因,它不会打印任何东西。 here is what I have: 这就是我所拥有的:

  {dataFormat.protein_questions.map((item, index) => (
        <div key={_.uniqueId()} className="item">
         <div className="inline fields">
           <Field
              onChange={handleChange}
              name={`protein_question[${index}].units_of_measurement`}
              component="select"
              className="ui dropdown2"
              required>

                 {item.typing_methods.map((method, methodIndex) => {
                    method.unitsOfMeasurement.map((unit, unitIndex) => (
                       <option value={unit.title}>{unit.title}</option>
                    ));
                 })}

          </Field>
         </div>
       </div>
  ))}

The options are not printing any data inside the select for some reason. 由于某种原因,选项不会在选择内部打印任何数据。 When I console log the data inside the nested loop it shows fine. 当我在控制台中记录嵌套循环内的数据时,它显示正常。 Anyone know why this is happening? 任何人都知道为什么会这样吗?

By the way this is inside my render function in a JSX view file. 顺便说一下,这是在JSX视图文件中的render函数内部。

It looks like you forgot return before method.unitsOfMeasurement... : 它看起来像你忘了returnmethod.unitsOfMeasurement...

{item.typing_methods.map((method, methodIndex) => {
  return method.unitsOfMeasurement.map((unit, unitIndex) => (
    <option value={unit.title}>{unit.title}</option>
  ));
})}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM