【发布时间】:2021-09-08 20:16:20
【问题描述】:
我正在开展一个项目,在该项目中我传递了一份关注点列表和一份客户关注点列表。我正在尝试在编辑视图中检查与客户关注点匹配的所有关注点。这里的想法是,我可以列出所有可能的问题,并预先检查客户的问题。但是我似乎无法让它工作。下面的代码是我正在使用的,但这只是创建了关注列表的 4 个副本。任何帮助将不胜感激。
ClientController.php
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Client $client
* @return \Illuminate\Http\Response
*/
public function edit(Client $client)
{
//
$concerns = Concern::all();
return Inertia::render('Client/Edit',
[
'client' => $client::with('concerns')->get()->first(),
'concerns' => $concerns,
]
);
}
客户端/Edit.Vue
<ul id="concerns">
<li v-for="(concern,id) in concerns" v-bind:key="id">
<span v-for="(cc, id) in client.concerns" v-bind:key="id">
<span v-if="concern.id === cc.id">
<input type="checkbox" :name="concern.concern_slug" :value="concern.id" v-model="form.concerns" checked /><label :for="concern.concern">{{ concern.concern }}</label>
</span>
<span v-if="concern.id !== cc.id">
<input type="checkbox" :name="concern.concern_slug" :value="concern.id" v-model="form.concerns" /><label :for="concern.concern">{{ concern.concern }}</label>
</span>
</span>
</li>
</ul>
...
<script>
import BreezeAuthenticatedLayout from '@/Layouts/Authenticated.vue'
import BreezeCheckbox from '@/Components/Checkbox.vue'
import { Head } from '@inertiajs/inertia-vue3';
import VueGoogleAutocomplete from 'vue-google-autocomplete'
export default {
props: {
errors: Object,
concerns: Object,
client: Object,
clientConcerns: Object,
},
data () {
return {
form: {
first_name: this.client.first_name,
last_name: this.client.last_name,
email: this.client.email,
address: this.client.address,
city: this.client.city,
postal_code: this.client.postal_code,
province: this.client.province,
preferred_day: this.client.preferred_day,
preferred_time: this.client.preferred_time,
preferred_frequency: this.client.preferred_frequency,
goals: this.client.goals,
concerns: [],
},
}
},
...
</script>
【问题讨论】: