大家好,我有一个状态要推送到数据库:
state = {
formName: '',
inputs: [
{
inputLabel: 'label',
inputType: 'text',
inputValue: 'value'
}
],
};
这基本上是一个表单名称,它是一个字符串和一个对象数组,其中包含3个字段,它们是字符串(大小不同,因为我制作了一个应用程序,添加了用户想要的数量), 而且我想将数组发送到mongoDB以建立自己的架构:
const ItemSchema = new Schema({
formName:String,
inputs: [
{
inputLabel: {
type: String,
required: true
},
inputType: {
type: String,
required: true,
enum: ['text', 'color', 'date', 'email', 'tel', 'number']
},
inputValue: {
type: String,
required: true
}
}
]
});
我的目标是拥有一个表单名称和一个输入对象数组,
我的模式正确吗?以及如何将其推入那里? 这就是我到目前为止所得到的:
sendingData=()=>{
var inputs=this.state.inputs;
fetch('/api/items',{
method:'POST',
body:JSON.stringify({})
})
}