2017-11-04 5 views
2

私はnormalizrを使用しています。私は文字列を正規化しようとしますが、私は理解しませんでした。 (それは間違っているので注意してくださいconversationIdSchemaに動作していない)私はこのようなconversationIdsを持っていると思っていnormalizr文字列にすることはできますか?

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

を::

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]); 

今上記のコードは、その結果、以下の私に与える

{ 
    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は文字列ではなくオブジェクトで動作します。

関連する問題