у меня было вычисленное свойство, равное studScore
и scores
, где
studScore
вычисляет все вставленные значения, которые я динамически вставил, используя push()
. пока;
scores
вычисляет данные, поступающие из DB .
//DATA from DB
props:['students','index']
activities:[
{"id":174,"activity_title":"1","schedule_id":1,
"scores":
[
{"id":495,"scores":"3","student_id":1,"activity_id":174,},
{"id":496,"scores":"4","student_id":2,"activity_id":174,},
{"id":497,"scores":"5","student_id":3,"activity_id":174}]}
]
//i use this push to insert new input template so ican insert new data
this.activities.push({ activity_title: [], scores: [], id: null, });
computed: {
//this function compute all newly added data in my input template
studScore: function() {
return this.students.map((c, index) => {
return this.activities.reduce((acc, item) => {
const value = parseFloat(item.scores[index], 10) || 0;
return acc + value;
}, 0);
});
},
//this compute the the total scores coming from DB
scores: function() {
return this.students.map((c, index) => {
return this.activities.reduce((acc, item) => {
const value = parseFloat(item.scores[index].scores, 10) || 0;
return acc + value;
}, 0);
});
},
},
//template
<td class v-for="(quiz,i) in activities" :key="i">
<input v-if="!quiz.scores[index]" v-model="quiz.scores[index]" />
<input v-else-if="quiz.scores[index].scores" v-model="quiz.scores[index].scores" />
<input v-else v-model="quiz.scores[index]" autocomplete="off" />
</td>
Когда я пытался вставить новый input
, когда push()
Я получил ошибку в моих scores
функциях баллов: "(ошибка во время оценки)" . Я получаю эту ошибку, потому что она бьет третий input
в моем шаблоне, но я не знаю, как я могу решить эту проблему.