- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 API,它使用 fields 属性中的属性提供这样的数据。
{
records: [
{
id: "123",
fields: {
author: {
id: "1",
name: "Paul"
},
title: "My awesome blog post",
comments: [
{
id: "324",
commenter: {
id: "2",
name: "Nicole"
}
}
]
}
}
]
};
processStrategy: (input, parent, key) => input.fields
来处理这个问题。但我想再次非规范化,以便非规范化实体包含此字段结构,因为 API 期望它以这种方式。
const denormalizedData = denormalize([123], [article], normalizedData.entities)
对我的规范化数据进行非规范化处理省略字段:
[
{
"author": {
"id": "1",
"name": "Paul"
},
"title": "My awesome blog post",
"comments": [
{
"id": "324",
"commenter": {
"id": "2",
"name": "Nicole"
}
}
]
}
]
最佳答案
因为 processStrategy
用于规范化过程中的数据预处理,不会在非规范化过程中执行。对于您的用例,我不会使用此功能,而是简单地按如下方式构建您的架构:
const { schema, denormalize, normalize } = normalizr;
const user = new schema.Entity("users");
const comment = new schema.Entity("comments", { commenter: user });
const commentList = [comment];
const post = new schema.Entity("posts", {
fields: { author: user, comments: commentList }
});
const postList = [post];
const mockApiResponse = {
records: [
{
id: "123",
fields: {
author: {
id: "1",
name: "Paul"
},
title: "My awesome blog post",
comments: [
{
id: "324",
commenter: {
id: "2",
name: "Nicole"
}
}
]
}
}
]
};
const normalizedResponse = normalize(mockApiResponse.records, postList);
const denormalizedResponse = denormalize(
normalizedResponse.result,
postList,
normalizedResponse.entities
);
console.log("normalizedResponse", normalizedResponse);
console.log("denormalizedResponse", denormalizedResponse);
axios
用他们的
transformRequest
解决了这个问题特征。
关于normalizr - 反规范化逆向过程策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53704982/
我有一个 Windows 应用程序,它使用此 C 代码的反向(下面的解码)来加密用户密码: static void PasswordDecode(char * szPassword) { char s
我目前正在尝试“破解”一个 Linux 嵌入式设备。此设备有一个不应使用的 telnet 守护程序。不管怎样,我已经从制造商网站上获取了二进制固件并成功地提取了根文件系统。顺便说一下,我现在有了/et
前言 你可以独善其身 但你不能兼济天下 。 简介 其实这部分是使用教程,github上面有备份的下载链接,只是可能不更新了,V2.2安装之后 一把快刀,很简洁的界面 点击界面里
我在具有相关质量的 3D 框中有几个点(x、y、z 坐标)。我想绘制在给定半径 R 的球体中发现的质量密度直方图。 我已经编写了一个代码,如果我没有犯任何我认为我可能有的错误,它的工作方式如下: 我的
我有一个代码函数,我试图扭转它的影响,但没有成功。我原来的功能是: ror al,1 // rotates the al part of
我想知道,是否有任何指南可用于识别应用程序二进制文件中与符号链接(symbolic link)相关的函数? 我们以BusyBox为例,/bin/ping是/bin/BusyBox的符号链接(symbo
所以我在查看一个受感染的 WordPress 网站时看到了这个注入(inject)的 js。它基本上进行了一轮混淆(charCodeAt(13-3,9-2等)。然后,它输出以下内容: var key
我在尝试获取引用未审计实体的审计实体时遇到问题。在我们的应用程序中,某些实体是在不使用 hibernate 的情况下引导的,这些实体是我们的元模型,不需要审计。 工作示例: public class
背景: 我们有一个基于 maven 的 java 项目,目标是 JRE 1.7,但是源代码使用了 lambda,所以我们使用 retrolambda 来转换 Java 8 源代码到 Java 7。我们
我是一名优秀的程序员,十分优秀!