嘿我正在尝试将数组放入数组中,并且它们都是混合类型,这就是我如何构建它
var Fields = new Schema({
type: {type: String},
length: {type: Number},
lable: {type: String},
name: {type: String}
});
var Fieldsets = new Schema({
label: {type: String},
name: {type: String},
fields: {type: [Fields]}
});
var Steps = new Schema({
order: {type: Number},
name: {type: String},
fieldsets: {type: [Fieldsets]}
});
var FormSchema = new Schema({
name: {
type: String,
default: '',
trim: true
},
created: {
type: Date,
default: Date.now
},
steps: {type: [Steps]}
});
然后我使用这个,通过postman(chrome扩展名)发布此
{
"name": "Reg Form",
"steps": [
{
"order": "1",
"name": "Login Information",
"fieldsets": {
"label": "Username and password",
"name": "username_password",
"fields": {
"type": "text",
"length": "256",
"lable": "Username",
"name": "username"
}
}
},
{
"order": "2",
"name": "Check check",
"fieldsets": {
"label": "Email and age",
"name": "email_age",
"fields": {
"type": "text",
"length": "256",
"lable": "email",
"name": "email"
}
}
}
]
}
结果如下:
[
{
"_id": "534964bd55da09f8144d43ac",
"__v": 0,
"steps": [],
"created": "2014-04-12T16:07:25.780Z",
"name": "Reg Form"
}
]
为什么?
我试图制作一个步骤的数组,其中包括字段集内部字段,我不明白为什么它不会继续。 谢谢!
答案 0 :(得分:0)
我对此不熟悉,但请尝试代替steps: { type: [ Steps ] }
执行steps: [ Steps ]
并使用相同的字段