2017-11-04 113 views
2

我正在使用normalizr。我尝试正常化字符串,但我没有弄清楚。是否可以normalizr字符串?

const mails = [ 
    { 
    "id": "mailId1", 
    "conversationId": "conversationId1", 
    "content": "Hi", 
    "sender": { 
     "emailAddress": { name: 'Jack', address: '[email protected]' } 
    } 
    }, 
    { 
    "id": "mailId2", 
    "conversationId": "conversationId1", 
    "content": "Hello", 
    "sender": { 
     "emailAddress": { name: 'Rose', address: '[email protected]' } 
    } 
    } 
] 

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不工作,因为它是错误的)

{ 
    result: { mails: ['mailId1', 'mailId2'] }, 
    entities: { 
    users: { 
     '[email protected]': { name: 'Jack', address: '[email protected]' } 
     '[email protected]': { name: 'Rose', address: '[email protected]' } 
    }, 
    mails: { 
     // ... 
    } 
    } 
} 

我希望能有这样的conversationIds:

{ 
    result: { mails: ['mailId1', 'mailId2'] }, 
    entities: { 
    users: { 
     '[email protected]': { name: 'Jack', address: '[email protected]' } 
     '[email protected]': { name: 'Rose', address: '[email protected]' } 
    }, 
    mails: { 
     // ... 
    }, 
    conversationIds: ['conversationId1'] 
    } 
} 

回答

1

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

相关问题