简体   繁体   English

我从 API 获取数组,但是当我尝试在表中显示它时它显示空数组(noob ReactJs)

[英]I GET array from API but when i try show it in the table it show me empty array (noob ReactJs)

I created a Be api I that exist a Get request to get all the tasks from this API,我创建了一个 Be api 我存在一个 Get 请求以从这个 API 获取所有任务, 在此处输入图像描述

{
"tasks": [
    {
        "_id": "5f0b19c11f072e0984459ff5",
        "title": "some Edited random stuff ",
        "description": "some Edited random stuff",
        "creater": "vladi",
        "__v": 0
    },
    {
        "_id": "5f0b19d71f072e0984459ff6",
        "title": "vladi task ",
        "description": "vladi description",
        "creater": "vladi",
        "__v": 0
    }  ]

in my TaskReducer i make it在我的 TaskReducer 中,我做到了

tasks: {
  tasks: []
  },

now in my fronted page i ask to see it all in a table现在在我的首页中,我要求在表格中查看所有内容

 <tbody>
                    {this.props.tasks.tasks.map((task, taskID) =>
                        <tr key={taskID}>
                            <th scope="row" >  2{task.title}</th>
                            <td >3{task.description}</td>
                            <td >4{task.creater}</td>
                            <td >5{task.dateCreated}</td>

                            <td >
                                <span className="pointer" onClick={() => this.handlerClickDeleteTask(task.taskID)}>delete  </span>
                                <span className="pointer" onClick={() => this.handlerClickViewTask(task.taskID)}>edit  </span>
                                <span className="pointer" onClick={() => this.handlerClickEditTask(task.taskID)}>view  </span>
                            </td>
                        </tr>

                    )}

                </tbody>

but when i open the table it look empty (even not showing the numbers there) this is the link to the repository if someone have idea or think need more https://github.com/VladiKonovalov/Fronted/blob/master/src/containers/Tasks.js但是当我打开表格时它看起来是空的(甚至没有显示那里的数字)如果有人有想法或认为需要更多https://github.com/VladiKonovalov/Fronted/blob/master/src/ ,这是存储库的链接容器/Tasks.js

under usersActions.js file you are setting users instead of tasks.usersActions.js文件下,您正在设置用户而不是任务。

case "SET_TASKS":
    state = { ...state, users: action.payload }
    break;
default:

it should be like:它应该是这样的:

case "SET_TASKS":
    state = { ...state, tasks: action.payload }
    break;
default:

暂无
暂无

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

相关问题 fetch 给了我一个完整的数组,但是当我尝试访问它时它是空的 - fetch gives me a full array but it is empty when i try to access it firestore:当我尝试按日期获取数据时,数组为空 - firestore: array empty when i try to get data by date 来自 API 调用的数据存储在一个数组中,但是当我尝试在 function 中使用该数组以供进一步使用时,它显示该数组为空。 为什么? - Data from API call are stored in a Array but when i try to use that array in a function for further use it shows that array is empty . why? 在 ReactJS 的表格行中显示数组数据 - Show array data in Table rows in ReactJS 当我尝试通过索引访问数组元素时,它给了我未定义的 - when i try to access array element by index it gives me undefined 如何显示来自数组reactjs的数据? - How to show data from array reactjs? 有没有一种方法可以让我从一个带有函数的 API 数组中的对象获取信息,以便我可以在 HTML 上显示它? - Is there a way where i can get information from an Object within an Array of an API with a function so that i can show it on the HTML? 当模板中的数组值为空或长度=== 0时,如何显示输入框? - How can i show input boxes when the array values are empty or length === 0 in my template? KnockoutJS:当返回的数组为空时显示消息 - KnockoutJS: Show message when the returned array is empty 单击时显示数组中的最后一个索引(在继续更新的数组中) - Show the last index in an array when I click (in an array that continues to be updated)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM