简体   繁体   English

如何在数组es6 reactjs中推送td

[英]How to push td in array es6 reactjs

I staring to build the some project but the ploblem is i can't push the tag to the array 我正盯着建一些项目,但问题是我无法将标签推入阵列

const createData = _.map(this.props.users, (user, index) => {
      let array = []
      _.map(user.user, (i, index2) => {
        array.push(
          <td>{i.name}</td>
          <td>{i.total_hour}</td>
          <td>{i.manday}</td>
        )
      })
      return (
        <tr key={index}>
          <td>{user.position}</td>
          {array}
        </tr>
      )
    })

How does the way can i do that 我该怎么做

jsx doesn't support this following syntax, you should a parent to include them. jsx不支持以下语法,您应该将其包括在内。

<td>{i.name}</td>
<td>{i.total_hour}</td>
<td>{i.manday}</td>

So you should change your code like this way: 因此,您应该像这样更改代码:

const createData = _.map(this.props.users, (user, index) => {
  let array = []
  _.map(user.user, (i, index2) => {
    array.concat([i.name, i.total_hour, i.manday])
  })
  return (
    <tr key={index}>
      <td>{user.position}</td>
      {
        array.map((one, i) => {
          reutrn <td key={i}>one</td>
        })
      }
    </tr>
  )
})

.map returns an array. .map 返回一个数组。 You can use 您可以使用 .each and push each element like this. .each并像这样推动每个元素。

const createData = _.map(this.props.users, (user, index) => {
  let array = []
  _.each(user.user, (i, index2) => {
    array.push(
      <td>{i.name}</td>
      <td>{i.total_hour}</td>
      <td>{i.manday}</td>
    )
  })
})

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

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