【发布时间】:2021-05-10 11:44:41
【问题描述】:
我正在尝试创建一个“编辑列表”页面,其中显示某人提交的信息。我对如何通过选中第一次选中的框来填充表单中的复选框感到有些困惑。
我知道复选框会查找 false/true 以显示支票,但我的数组如下: [x,y,z] 仅显示为 [true] 或 [false] 导致所有使用 v-model 时会同时检查框,反之亦然。
表格
<input
type="checkbox"
id="Set Photographer"
value="Set Photographer"
v-model="returnedListing[0].crew_positions"
/>
<label for="Set Photographer">Set Photographer</label>
<input
type="checkbox"
id="Producer"
value="Producer"
v-model="returnedListing[0].crew_positions"
/>
<label for="Producer">Producer</label>
<input
type="checkbox"
id="Production Designer"
value="Production Designer"
v-model="returnedListing[0].crew_positions"
/>
<label for="Production Designer">Production Designer</label>
返回列表
const [actors, returnedListing] = await Promise.all([
$axios.$get(`/api/v1/actors/`, {
params: {
user: body
}
}),
$axios.$get(`/api/v1/listings/`, {
params: {
random_public_id: params.id
}
})
]);
return { actors, returnedListing };
虚拟 API 对象
{
"id": 15,
"title": "NUmber 15",
"start_date": "2021-03-04",
"end_date": "2021-02-16",
"location": "The Bronx",
"overview": "sdfds",
"studio": "sdfdsf",
"poster": null,
"crew_positions": "Set Photographer, Producer, Production Designer",
"post_production_positions": "Editing, AD",
"random_public_id": null,
"date_submitted": null,
"user": 1
}
基本上我想弄清楚如果它的值是 ['Set Photographer', 'Producer'] 并在“Production Designer”保持未选中状态时选中这两个框,如何循环返回Listing[0].crew_positions。
【问题讨论】:
-
您能分享一下您的数据是什么样的吗?
-
@PriyankKachhela 当然,刚刚做了
-
所以首先你需要将
crew_positions使用string的split方法转换成数组,然后你可以使用数组的includes方法来检查值是否在数组中。
标签: javascript vue.js vuejs2