[英]Write and read data from Javascript object
I have the following small setup in Svelte:我在 Svelte 中有以下小设置:
Calendar and checkboxes work.日历和复选框有效。 What I am trying to understand is the best way to read and store the option responses for each date that is selected by the user.
我想了解的是读取和存储用户选择的每个日期的选项响应的最佳方式。
Here is what I currently have in my svelte file:这是我目前在我的 svelte 文件中的内容:
<script>
import Datepicker from "praecox-datepicker";
import { onMount } from 'svelte';
export let name;
let day;
let questions = [
{value: "Condition 1", checked: false},
{value: "Condition 2", checked: false},
{value: "Condition 3", checked: false},
{value: "Condition 4", checked: false}
];
let selectedQuestions = [];
$: questions = {...questions,
[day]: [
{value: "Condition 1", checked: false},
{value: "Condition 2", checked: false},
{value: "Condition 3", checked: false},
{value: "Condition 4", checked: false},
]
};
$: {
selectedQuestions = questions.savedValues[day]
};
$: selectedQuestions = Object.fromEntries(Object.entries(questions).filter(([key, value]) => key == day))
$: day = day;
$: readDate = new Date(day);
$: mm = readDate.toLocaleString("en-US", {month: "long"});
$: dd = readDate.toLocaleString("en-US", {day: "numeric"});
$: yyyy = readDate.toLocaleString("en-US", {year: "numeric"});
onMount(async () => {
day = new Date()
});
</script>
<main>
<div class="row">
<div class="col-sm">
<Datepicker pickerRule='singleChoice' bind:pickerResult={day}/>
</div>
<div class="col-sm">
<p>{mm} {dd}, {yyyy}</p>
<ul>
{#each questions as question}
<li>
<input type=checkbox checked={question.checked}>
{question.value}
</li>
{/each}
</ul>
</div>
</main>
The current issue is I'm not sure how to access the filtered object and if I'm even accessing that properly.当前的问题是我不确定如何访问过滤后的 object 以及我是否能够正确访问它。
To recap the workflow would need to handle the following:回顾一下工作流程需要处理以下内容:
You need:你需要:
1.Upgrade praecox-datepicker
to version 1.0 or higher. 1.将
praecox-datepicker
datepicker升级到1.0或更高版本。
2.Use bind:selected
to get the selected result. 2.使用
bind:selected
获取选中的结果。
3.Pass the selection result (start date) to the viewDate
property to keep the view synchronized. 3.将选择结果(开始日期)传递给
viewDate
属性,保持视图同步。
4.If you want a timely response, please submit an issue directly on Github. 4.如需及时回复,请直接在Github提交issue。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.