【发布时间】:2016-11-27 17:02:46
【问题描述】:
我在流星简单模式中多次看到这种“标签”用法。只是不知道我们为什么需要这样一个字段。
const Product = new SimpleSchema({ _id: {
type: String,
label: "Product ID" } })
谢谢
德里克
【问题讨论】:
标签: meteor simple-schema
我在流星简单模式中多次看到这种“标签”用法。只是不知道我们为什么需要这样一个字段。
const Product = new SimpleSchema({ _id: {
type: String,
label: "Product ID" } })
谢谢
德里克
【问题讨论】:
标签: meteor simple-schema
如果您仅使用简单模式,label 将纯粹用于显示@Khang 回答的更人类可读/可理解的错误消息格式。
如果您使用 autoform 基于简单模式生成 for,则理想情况下,该字段的标签将根据简单模式中定义的内容自动生成。但是如果你想更详细地展示它,你可以通过专门定义标签来覆盖它。
例如:
userName :{
type: String,
...
}
将生成一个带有输入文本框的表单。该输入框的标签默认为“用户名”
userName:{
type: String,
label: "someTextHere",
...
}
会生成一个输入文本框。这个输入框的标签现在将是“someTextHere”而不是“用户名”
【讨论】:
IMO 标签是字段的可读名称,它有助于代码更具语义。它在调试时也很有帮助,例如,如果您有一个架构字段,例如:
// ...
appId: {
type: String,
},
// ...
如果您在插入时没有提供appId 值,您将收到此错误Error: App id is required。可能很难知道出了什么问题,因为 SimpleSchema 会自动重新格式化字段名称。如果您提供标签字段:
// ...
appId: {
type: String,
label: 'App Id of the document',
},
// ...
那么错误信息会是:Error: App Id of the document is required,这个信息比较容易找到问题。
【讨论】:
这适用于 Autoform 包:https://github.com/aldeed/meteor-autoform
所以除非你使用它,否则你不需要它。
【讨论】: