Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 访问对象数组中对象的ID,ReactJS_Javascript_Reactjs - Fatal编程技术网

Javascript 访问对象数组中对象的ID,ReactJS

Javascript 访问对象数组中对象的ID,ReactJS,javascript,reactjs,Javascript,Reactjs,我试图通过使用map循环从mongoDB集合中检索\u id,但问题是它给了我未定义的。 有什么建议吗 render() { const {itemsPerPage, currentPage, todos} = this.state; const end = currentPage * itemsPerPage const start = end - itemsPerPage const currentItems = todos.slice(start, end)

我试图通过使用
map
循环从mongoDB集合中检索
\u id
,但问题是它给了我
未定义的
。 有什么建议吗

render() {
    const {itemsPerPage, currentPage, todos} = this.state;
    const end = currentPage * itemsPerPage
    const start = end - itemsPerPage
    const currentItems = todos.slice(start, end);
    console.log('--------currentItems', currentItems);
    return <div className={"App"}>
        <div className="App-header">
            <h2>Welcome to To-Do List App</h2>
        </div>
        <input ref={this.inpRef} onKeyPress={this.handleKeyPress} name={''} type='text'/>
        <button onClick={() => this.addItem()} className={'btn btn-primary'}>Add</button>
        <ul>
            {
                currentItems.map(todoItem => {
                    return <ListItem
                    key={todoItem._id}
                    todoItem={todoItem}
                    deleteItem={this.deleteItem}
                    editItem={this.editItem}
                    submitEdit={this.submitEdit}
                />})
            }
            <div>
                {this.renderPagination()}
            </div>
        </ul>
    </div>
};
render(){
const{itemsPerPage,currentPage,todos}=this.state;
const end=currentPage*itemsPerPage
const start=end-itemsPerPage
const currentItems=todos.slice(开始、结束);
console.log('--currentItems',currentItems);
返回
欢迎使用待办事项列表应用程序
this.addItem()}className={'btn btn primary'}>Add
    { currentItems.map(todoItem=>{ 返回}) } {this.renderPagination()}
};
}

CurrentItems输出:
[{…},{…}]
0:{u id:“5ee33e6a5398c70ccf57f684”,todo:“a”,选中:false,{u v:0}
1:{u id:“5ee33e775398c70ccf57f685”,todo:“z”,选中:false,{u v:0}
长度:2

__proto_uu;:数组(0)

可能是数据存在一些异步问题。尝试退出渲染,直到
currentItems
包含数据

render() {
  ...
  {currentItems.length && <ul>
    {currentItems.map(todoItem => {...})}
   </ul>}
  ...
}
render(){
...
{currentItems.length&&
    {currentItems.map(todoItem=>{…}}
} ... }
如果您能给我们一个您的
控制台.log('------------currentItems',currentItems)
行的示例输出,这将有助于洛蒂更新帖子并在那里包含输出