【问题标题】:How to use schemaAttribute as a string for Array in normalizr如何在 normalizr 中使用 schemaAttribute 作为数组的字符串
【发布时间】:2018-05-27 07:31:00
【问题描述】:

我正在查看关于数组架构的 docs,在 schemaAttribute 选项下它说我们可以传递一个字符串,它对于一个架构是可选的。

我尝试了很多组合,但无法完成,出现错误或我的数据未正确规范化。

例如:

const adminSchema = new schema.Entity('admins');

const myArray = new schema.Array({
  new: adminSchema
}, 'new');

const myArray = new schema.Array(adminSchema, 'new');

我怎样才能做到这一点?

除此之外,还有什么原因?

【问题讨论】:

    标签: normalizr


    【解决方案1】:

    查看源代码后,我意识到如何使用它

    const data = [ { id: 1, type: 'admins' }, { the_ID: 2, type: 'users' } ];
    
    const userSchema = new schema.Entity('users', {}, {
      idAttribute: 'the_ID'
    });
    
    const adminSchema = new schema.Entity('admins');
    
    const myArray = new schema.Array({
      admins: adminSchema, users: userSchema 
    }, 'type');
    

    【讨论】:

      猜你喜欢
      • 2018-07-05
      • 2018-08-19
      • 2012-02-04
      • 2020-02-14
      • 2021-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多