Mongodb 将一系列值数据绑定到v-for中的对象

Mongodb 将一系列值数据绑定到v-for中的对象,mongodb,vuejs2,vue-component,vuex,Mongodb,Vuejs2,Vue Component,Vuex,我正在构建一个小应用程序来输入我的训练结果,以便进行一些分析。 我从mongodb实例中检索数据,如下所示(一次训练。一次训练只是由同一日期的所有训练组成): mongodb文档摘录 { "_id" : ObjectId("59d3b0a6250bb03934ddca46"), "date" : "2017-10-01", "exercise" : "Row", "sets" : [ { "resistance" : 42

我正在构建一个小应用程序来输入我的训练结果,以便进行一些分析。 我从mongodb实例中检索数据,如下所示(一次训练。一次训练只是由同一日期的所有训练组成):

mongodb文档摘录

{
    "_id" : ObjectId("59d3b0a6250bb03934ddca46"),
    "date" : "2017-10-01",
    "exercise" : "Row",
    "sets" : [ 
        {
            "resistance" : 42.5
        }, 
        {
            "resistance" : 45
        }, 
        {
            "resistance" : 47.5
        }
    ],
    "intensity" : 5
}
<table class="tbl tbl_border">
                    <tr>
                        <th>Exercise</th>
                        <th>Set 1</th>
                        <th>Set 2</th>
                        <th>Set 3</th>
                        <th>Set 4</th>
                    </tr>
                    <tr v-for="(exercise, exercise_index) in exercises">
                        <th>{{exercise.exercise}}</th>
                        <td v-for="(set, set_index) in exercise.sets" class="tbl_set tbl_border">
                            <p v-if= "edit == false">{{set.resistance}}</p>
                            <input v-else type="text" 
                            :placeholder="set.resistance" 
                            v-model="exercises">
                        </td>
                    </tr>
                </table>
                <button v-if= "edit == false" @click="enableEditMode"> Edit </button>
                <button v-else @click="saveAndExit"> Save </button>
前端代码生成训练列表(因此,日期…),我可以单击其中一个,根据训练值生成一个表格(因此,所有具有该日期的训练),并在编辑模式下使用以前的值自动填充字段,以防我要更正它们(就我所知,我将其限制为4组,因为将其全部包装在
v-for
循环中甚至无法动态生成列)

组件模板摘录

{
    "_id" : ObjectId("59d3b0a6250bb03934ddca46"),
    "date" : "2017-10-01",
    "exercise" : "Row",
    "sets" : [ 
        {
            "resistance" : 42.5
        }, 
        {
            "resistance" : 45
        }, 
        {
            "resistance" : 47.5
        }
    ],
    "intensity" : 5
}
<table class="tbl tbl_border">
                    <tr>
                        <th>Exercise</th>
                        <th>Set 1</th>
                        <th>Set 2</th>
                        <th>Set 3</th>
                        <th>Set 4</th>
                    </tr>
                    <tr v-for="(exercise, exercise_index) in exercises">
                        <th>{{exercise.exercise}}</th>
                        <td v-for="(set, set_index) in exercise.sets" class="tbl_set tbl_border">
                            <p v-if= "edit == false">{{set.resistance}}</p>
                            <input v-else type="text" 
                            :placeholder="set.resistance" 
                            v-model="exercises">
                        </td>
                    </tr>
                </table>
                <button v-if= "edit == false" @click="enableEditMode"> Edit </button>
                <button v-else @click="saveAndExit"> Save </button>
问题是:我现在可以编辑整个表(我想编辑),但如何将所有输入值绑定到
对象中(每行一个,以适合数据模型),以便在以后的函数中使用它们来发送HTTP请求

更新:这里的小提琴,几乎以相同的方式工作(它只是在同一时间获得所有的训练,因为后端按日期进行过滤):
我希望这能澄清它的工作原理。

1。-首先,您需要使用通过vuex检索的数据的本地副本。 你可以找到如何做到这一点

2.-然后可以将输入值绑定到该本地数据

<input v-else type="text" :placeholder="set.resistance" v-model="set.resistance">

运动
第1组
第2组
第三组
{{exercise.exercise}}

{{set.resistance}

编辑 拯救
我一直在反复尝试,但无法让它工作,我放了一把小提琴,也许是想弄清楚它应该如何工作。