A
A
Alexander Ivanov2019-09-19 23:50:35
React
Alexander Ivanov, 2019-09-19 23:50:35

Why is the array not shown in the template?

Why is the array not shown in the template?
I transfer I withdraw
<Body tmp={this.state.body.json.data}/>

render(){
        return (
                  Object.keys( this.props.tmp ).map( ( todo, index) =>
                          <div key={ index }>
                              <p>Name: {todo[index]}</p>
                          </div>
                    )
        )    
    }

Testing:
render(){
        
        return (
                  Object.keys( this.props.tmp ).map( ( todo, index) =>
                          <div key={ index }>
                              <p>Name: {todo} : {index}</p>
                          </div>
                    )
        )    
    }

Result:
5d84624fb7d30570361967.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hzzzzl, 2019-09-19
@hzzzzl

tmp is an array? then you don't need Object.keys t is already a separate element of the array, t[i] will be undefined

C
claimc, 2019-09-20
@claimc

Stepping through debugging will show what the values ​​of todo, index. You can add a line with the word debugger to this code; and launch the page with open DEVTOOLS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question