Mobx-状态树:如何将AnonymousModel重命名为商店名称

时间:2019-07-28 01:41:04

标签: javascript mobx mobx-state-tree

我正在使用mobx-state-tree,并且我想在出现错误而不是AnonymousModel时实际显示商店名称。

例如:

const data = {'123':{'name':'Part 1','size':'20','qty':'50'},'5678' :{'name':'Part 2','size':'15','qty':'60'},'9810' :{'name':'Part 2','size':'15','qty':'120'}};

const condition = ["5678", "9810"];

Object.keys(data).forEach(key => !condition.includes(key) ? delete data[key] : key);

console.log(data);

仍然给我一个类似

的错误
.as-console-wrapper { max-height: 100% !important; top: auto; }

但是我想得到

const SignupModel = types
  .model({
    isUsingFacebook: false,
    birthday: '',
    timeOfBirth: types.maybeNull(types.string),
    placeOfBirth: types.maybeNull(types.string),
    gender: types.maybeNull(types.string),
    password: '',
  })

1 个答案:

答案 0 :(得分:2)

只需将所需的名称作为第一个参数传递给'sourcePath' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR, 方法,就像这样:

model