我想从方法访问数据对象并修改数据对象内部的值,我想访问的对象名称来自函数参数模板<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 }我想要的是函数应该根据参数名称访问数据对象并修改原始对象
2 回答
慕勒3428872
TA贡献1848条经验 获得超6个赞
pObject不是this对象的属性- 它已作为参数传递给universalfunction函数。
universalfunction: function(pObject) {
this.pObject.elements.mistake = true;
}
添加回答
举报
0/150
提交
取消