我正在尝试创建一个具有可选的、可以为空的字符串值的模型。我两个都试过了
hint: types.optional(types.string, ""),和
hint: types.maybe(types.string),当我尝试将json对象设置为该对象时,这两种方法都会导致错误。如果我手动遍历json对象并将null内容设置为空字符串"“,则会起作用。
在路径"content“值处转换"jsoncontent”时出现
错误
null不可分配给类型:string(值不是字符串)。
发布于 2018-08-14 20:06:28
您可以使用types.maybeNull来拥有也可以是null的类型。
hint: types.maybeNull(types.string)发布于 2018-08-23 06:39:41
您可以使用以下解决方案之一在Mobx-State-Tree中拥有可为空的字符串值:
types.maybeNull(types.string) // value can be null或
types.optional(types.string, '') // should create empty string if value is not definedhttps://stackoverflow.com/questions/51840640
复制相似问题