【发布时间】:2018-08-28 15:33:39
【问题描述】:
我正在尝试使用 redux-saga 发布请求。我有两个输入的形式。我正在使用选择器从表单中收集输入数据,现在它是我的身体。但是我需要添加 itemId,它不是由用户输入的。我应该如何将它插入到body中?
我的传奇是这样的:
export function* submitForm() {
try {
const formType = 'item';
const body = yield select(makeSelectModifiedData());
let requestURL;
switch (formType) {
case 'item':
requestURL = 'http://localhost:1587/item';
break;
default:
}
const response = yield call(request, requestURL, { method: 'POST', body });
if (response.itemId) {
yield call(forwardTo, '/item');
}
} catch (error) {
Alert.error('Error message...', {
html: false,
});
}
}
【问题讨论】:
-
使用 body.itemId = 设置任何值
-
@AmruthLS,你能给我看个小例子吗,因为我整天都在尝试这个。我正在使用选择器,并且有一个完整的 json 对象。
-
我的意思是在这一行之后 const body = yield select(makeSelectModifiedData()); body.itemId =5 这样
-
@AmruthLS,它没有取值。
-
如果不将
const body更改为let body
标签: reactjs react-redux redux-saga