我在前端使用Vuetify,在后端使用Laravel。我试图创建一个动态表,用户可以在其中自己设置列名。因此,我创建了一个窗体,其中包含两个字段的循环:
<template>
<div>
<v-card>
<v-card-text>
<v-row v-for="n in numTextFields" align="center">
<v-col> <h3> Text {{ n }} </h3> </v-col>
<v-col> <v-text-field label="Bezeichnung" v-model="form.text.name[n]" > </v-text-field> </v-col>
<v-col> <v-switch label="Erforderlich" value="1" v-model="form.text.required[n]"></v-switch></v-col>
<v-col>Info</v-col>
</v-row>
{{ form }}
</v-card-text>
</v-card>
</div>
</template>
<script>
export default {
name: "SmartTableColumnSetting",
data() {
return {
numTextFields: 10,
form: {
text: {
name: [],
required: []
}
}
}
},
}
</script>
这给出了以下示例:
{ "text": { "name": [ null, "Input Text 1", null, null, null, null, null, "Input Text 7" ], "required": [ null, null, null, null, "1", null, "1" ] } }
我想要:
{"text": {
"type_1 :{
text: "Input Text 1"
required: 1
},
"type_2 :{
text: "Input Text 2"
required: 2
},
//and so on till 10
}
这可能吗?
或者我需要更改后端中的值吗?
正确的设置是什么?