Php 在Laravel中,当用户编辑表单时,如何使所有字段都可用(即使是空字段)?
我有一个使用Laravel和Vue JS框架创建的标准表单。我表单的一部分如下所示: 我已经创建了一个编辑页面,我的edit.blade.php如下所示:Php 在Laravel中,当用户编辑表单时,如何使所有字段都可用(即使是空字段)?,php,laravel,Php,Laravel,我有一个使用Laravel和Vue JS框架创建的标准表单。我表单的一部分如下所示: 我已经创建了一个编辑页面,我的edit.blade.php如下所示: <div> <project-form-for-desserts :all-desserts="{{ $allDesserts }}" :all-dessert-values="{{ $allDessertValues }}" :project="{{ $theProj
<div>
<project-form-for-desserts
:all-desserts="{{ $allDesserts }}"
:all-dessert-values="{{ $allDessertValues }}"
:project="{{ $theProject }}"
:project-property-values="{{ $theProject->dessertValues }}"
:project-photos="{{ $theProject->photos }}"
/>
</div>
<template>
<v-card>
<v-form>
<v-card>
<v-row>
<v-col>
<v-card-title>Name</v-card-title>
<v-text-field
v-model="theProject.name"
label="Please enter the dessert name"
/>
</v-col>
<v-col>
<v-card-title>Reference</v-card-title>
<v-text-field
v-model="theProject.type"
label="Please enter the dessert type"
/>
</v-col>
</v-row>
</v-card>
<v-card
v-for="selectDessertProperty in theProjectProperties"
:key="selectDessertProperty"
flat
>
<v-row>
<v-col>
<v-card-title>Name</v-card-title>
<v-select
v-model="theProject.property_values[selectDessertProperty]"
/>
</v-col>
</v-row>
</v-card>
<v-btn @click="addDessert"> Add </v-btn>
</v-form>
</v-card>
</template>
但是,当我转到特定项目的编辑页面时,它只显示最初填写的字段。它不显示空字段。如何解决此问题,使其同时显示已填写的输入字段和未填写的输入字段?
该表单如下所示:
<div>
<project-form-for-desserts
:all-desserts="{{ $allDesserts }}"
:all-dessert-values="{{ $allDessertValues }}"
:project="{{ $theProject }}"
:project-property-values="{{ $theProject->dessertValues }}"
:project-photos="{{ $theProject->photos }}"
/>
</div>
<template>
<v-card>
<v-form>
<v-card>
<v-row>
<v-col>
<v-card-title>Name</v-card-title>
<v-text-field
v-model="theProject.name"
label="Please enter the dessert name"
/>
</v-col>
<v-col>
<v-card-title>Reference</v-card-title>
<v-text-field
v-model="theProject.type"
label="Please enter the dessert type"
/>
</v-col>
</v-row>
</v-card>
<v-card
v-for="selectDessertProperty in theProjectProperties"
:key="selectDessertProperty"
flat
>
<v-row>
<v-col>
<v-card-title>Name</v-card-title>
<v-select
v-model="theProject.property_values[selectDessertProperty]"
/>
</v-col>
</v-row>
</v-card>
<v-btn @click="addDessert"> Add </v-btn>
</v-form>
</v-card>
</template>
名称
参考文献
名称
添加
表单字段的呈现出现问题。请显示控制表单和表单字段本身的代码。我在上面添加了表单的一部分。奇怪的是,最上面的两个条目,其中v-model=theProject.something总是显示在页面上,即使它们是空的,但是下面的字段没有显示。值得注意的是,其他字段都在循环中呈现。您正在循环的变量的内容是什么,项目属性是什么?如果将整个循环替换为{{theProjectProperties}},会发生什么情况?您是否看到了预期的属性数组或对象?如果是这样,用{{theProject.property_values[selectDessertProperty]}替换v-select,这样您就可以准确地看到传递给v-select的内容。它是否符合您的期望,并且符合v-select的期望?{{theProjectProperties}}显示了一个数组,其中是对象。因此,如果我有200个甜点,{{theProjectProperties}}里面是[{“id”:1,“甜点名称”:“蛋糊”,“甜点类型”:“奶油状”}{“id”:2等等……和以前一样,有不同的值……}……],这并没有显示任何东西可能是一个键。可能某些数据加载不正确,或者某些变量名或值未按预期对齐?如果您继续在屏幕上转储数据以进行浏览,或者如果愿意,使用vue devtools,您应该能够继续浏览您拥有的内容,并查看它是否符合您的预期。{{selectdesertproperty}正确吗?它的值是{{theProject.property_values}}中的一个键{{theProject.property_values}是一个数组还是一个对象,与您期望的键一样?