javascript - API 未更新表字段 - React Native App、AWS API 和 DynamoDB 表
问题描述
尝试使用我的“更新”API 更新我的 DynamoDB 表。它只是不工作。“更新”API 会将“状态”字段从“新建”更新为“已读”。API 没有问题,因为我在 Postman 上检查了它,并且它正确更新了该字段。
export const updateNotifications = (id) => {
if(id !== null){
const config = getAppConfig();
const cognitoToken = await getCognitoToken(config);
if (cognitoToken !== null) {
try{
let headers = {
'Content-Type': 'application/json',
'Authorization': cognitoToken,
'targetId': HAGo_getDeviceUUID(),
'userId' : id
};
let body = { 'status' : 'Read' }
let updateUrl = config["notification-update-api"] + '/' + id;
await fetch(updateUrl,
{
method: 'PATCH',
headers: headers,
body: body
})
} catch (e) {
// something went wrong
console.log('error');
}
}
}else{
return null;
}
}
我这样做对吗???请帮我修复我的代码!!!!
解决方案
解决它
解决方法:将json.stringify 给body 固定好。
export const updateNotifications = (id) => {
.
.
.
.
.
let body = json.stringify({ 'status' : 'Read' })
await fetch(updateUrl,
{
method: 'PATCH',
headers: headers,
body: body
}
}
推荐阅读
- reporting-services - 预览报告中的 SSRS 缺少单元格值
- javascript - 获得跨度索引后,如何突出显示选定的跨度并打印选定的文本?
- java - 如何升级 Spring Tool Suite 版本而不是重新安装?
- reactjs - 使用未定义的选择器
- python - GitPython获取开始sha1和结束sha1之间范围内的所有提交
- r - 申请R中文件夹中的pdf文件
- json - Json 模式未验证/使用子模式
- python - 如何确保某些模型实例始终存在于 django 数据库中?
- c# - .Net/C# Google ML/翻译异常:无法连接到所有地址
- reactjs - 尝试 i18next react 我可以加载 json 文件但翻译函数返回未更改的字符串