Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.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 PUT请求成功,但响应失败,Redux应用程序崩溃_Javascript_Reactjs_Redux_Put - Fatal编程技术网

Javascript PUT请求成功,但响应失败,Redux应用程序崩溃

Javascript PUT请求成功,但响应失败,Redux应用程序崩溃,javascript,reactjs,redux,put,Javascript,Reactjs,Redux,Put,我有一个React,Redux应用程序,应该作为CRUD应用程序使用。CRUD应用程序的一部分是更新东西的能力,这就是我目前遇到的问题。PUT请求起作用(可以看到Robomongo中的变化),但我的应用程序随后崩溃,问题在于我的减速机未处理的拒绝(TypeError):无法读取未定义的属性“item”(是的,item不是最佳命名,抱歉) 我想引导您完成PUT请求的过程,因为毕竟code>text 我将从我的动作被创建的地方开始,因为我想你会发现我有一个表单作为我合法的起点 所以,下面是我的行动(

我有一个React,Redux应用程序,应该作为CRUD应用程序使用。CRUD应用程序的一部分是更新东西的能力,这就是我目前遇到的问题。PUT请求起作用(可以看到Robomongo中的变化),但我的应用程序随后崩溃,问题在于我的减速机<代码>未处理的拒绝(TypeError):无法读取未定义的属性“item”(是的,
item
不是最佳命名,抱歉)

我想引导您完成PUT请求的过程,因为毕竟
code>text

我将从我的动作被创建的地方开始,因为我想你会发现我有一个表单作为我合法的起点

所以,下面是我的行动(为代码墙感到抱歉)

行动: 这是我的减速机

减速器: 因此,错误发生在我的reducer中(我添加了一条注释),我真的不明白为什么,现在当PUT请求更改数据库中的数据时。我想我遗漏了一些愚蠢的东西,但我无法修复它。非常感谢所有帮助,如果需要更多代码/信息,请告诉我

谢谢你的阅读

编辑: 下面是我的
对象的外观:

在减速器中,您期望和
动作
的形状为:
{type:'something',payload:'something other'}

但是,当您分派操作时,您没有
有效负载的属性

这是您正在发送的内容:

{
  ...door, // this will spread all properties of door (which doesn't have a property with the name payload)
  custom_name,
  location
}
然后您尝试访问
action.payload.item
,因此您会得到错误:

无法读取未定义的属性“item”


有效载荷
从未在您的
操作中定义过(顺便说一句,
也没有定义过)。

两个问题:1。门的形状是什么?2.是
state.fetchDoors
对象吗?(我想知道为什么它叫
fetch…
)@Sag1v“shape”是什么意思?是
状态。fetchDoors
是一个对象。我是从我的redux store.shape中获取它的,该对象具有哪些属性?例如:
{a:'foo',b:'bar'}
@Sag1v哦,我明白了。我希望可以发布一个看起来像这样的截图。请看我的编辑。谢谢你的时间。我在那里没有看到任何
项目
属性……是的,你完全正确。哦,老兄,我现在觉得自己很傻。我更新了代码并将其重命名为:
item:action.doorPayload
item:action.controllerPayload
。非常感谢你。
const initialState = {
  isLoading: false
}

export const settings = (state = initialState, action) => {
  switch (action.type) {
    case 'DOOR_UPDATING':
      return { ...state, isLoading: true }

    case 'DOOR_UPDATED_SUCCESS':
      return { ...state, item: action.payload.item, isLoading: false } // Here's where the error occurs

    case 'CONTROLLER_UPDATING':
      return { ...state, isLoading: true }

    case 'CONTROLLER_UPDATING_SUCCESS':
      return { ...state, item: action.payload.item, isLoading: false }
    default:
      return state
  }
}
{
  ...door, // this will spread all properties of door (which doesn't have a property with the name payload)
  custom_name,
  location
}