normalizr字符串是否可能?

时间:2017-11-04 03:52:00

标签: javascript normalizr

我正在使用normalizr。我试着规范化字符串,但我没弄明白。

('A4 paper (canon):', 8.9)

现在上面的代码会给我以下结果:

(注意let fileManager = FileManager.default // Get current directory path let path = fileManager.currentDirectoryPath print(path) 无效,因为它错了)

const mails = [
  {
    "id": "mailId1",
    "conversationId": "conversationId1",
    "content": "Hi",
    "sender": {
      "emailAddress": { name: 'Jack', address: 'jack@example.com' }
    }
  },
  {
    "id": "mailId2",
    "conversationId": "conversationId1",
    "content": "Hello",
    "sender": {
      "emailAddress": { name: 'Rose', address: 'rose@example.com' }
    }
  }
]

const userSchema = new schema.Entity('users', {}, {
  idAttribute: value => value.emailAddress.address
});
const conversationIdSchema = new schema.Entity('conversationIds', {}, {
  idAttribute: value => value
});
const mailSchema = new schema.Entity('mails', {
  conversationId: conversationIdSchema,
  sender: userSchema
});

const normalizedData = normalize(mails, [mailSchema]);

我希望有像这样的对话:

conversationIdSchema

1 个答案:

答案 0 :(得分:1)

不,这是不可能的。 Normalizr适用于对象,而不是字符串。