我想从方法访问数据对象并修改数据对象内部的值,我想访问的对象名称来自函数参数
模板
<tbody>
<td>B</td>
<td>High Kick Fwd</td>
<td>{{kal.totalPoints}}</td>
<template v-for="elements in kal">
<td
v-for="item in elements"
:key="elements[item]"
@click="universalfunction(kal)" // passing the object
:class="{red:item.mistake,green:!item.mistake}"
class="workingElemments"
>{{item.Marks}}</td>
</template>
<td>{{parseFloat(kal.markObtain).toFixed(2)}}</td>
</tbody>
data: function() {
return {
kal: {
elements: {
below90: { mistake: false, Marks: 0.4 },
bodyPosition: { mistake: false, Marks: 0.2 },
toeFlex: { mistake: false, Marks: 0.1 },
Hezitation: { mistake: false, Marks: 0.1 }
},
totalPoints: 1,
markObtain: 1.0
}
}
universalfunction: function(pObject) {
this.pObject.elements.mistake = true; //error: cannot access the elements of undefined
}
我想要的是函数应该根据参数名称访问数据对象并修改原始对象
慕勒3428872
相关分类