我正在为查看学院详细信息的功能编写代码,它显示该学院的专业数量。如何在模板中计算数组?
I'm coding for the function to see the Faculty's details and it shows number of majors of that faculty. How to count array with in template?
I'm coding for the function to see the Faculty's details and it shows number of majors of that faculty. I don't know how to count array majors with v-if and v-for. Please help me fix that. Many thanks.
模板标签
<tr>
<td>Sumary:
<strong v-for="major in majors">
<strong v-if="form.faculty_code==majors.major_faculty">
{{ major }}
</strong>
</strong>
</td>
</tr>
脚本标签
data() {
return {
faculties:[],
majors:[],
form: new Form({
faculty_id:'',
faculty_code:'',
faculty_name:'',
faculty_status: '',
}),
};
},
mounted() {
this.fetchMajors();
this.fetchFaculties();
},
methods: {
fetchFaculties(page_url) {
let vm = this;
page_url = '../../api/admin/edu-faculty/faculty/'+this.currentEntries+'?page='+this.pagination.current_page;
fetch(page_url)
.then(res => res.json())
.then(res => {
this.faculties = res.data;
this.pagination = res.meta;
})
.catch(err => console.log(err));
},
fetchMajors(page_url) {
let vm = this;
page_url = '../../api/admin/edu-major/chuyen-nganh/major';
fetch(page_url)
.then(res => res.json())
.then(res => {
this.majors = res.data;
})
.catch(err => console.log(err));
},
}
要仅获取具有给定教员代码的专业数量,您可以在 mounted() 函数中使用
this.total.majors = 0;
this.majors.forEach((element) => {
element.major_faculty == this.faculty_code ? this.total_majors += 1 : ""
});
感谢观看和帮助我。我找到了解决方案。
模板标签
<tr>
<td>Sumary:
<strong>
{{ countA.length }}
</strong>
</td>
脚本标签
computed: {
countA() {
return this.majors.filter(major => major.major_faculty==this.form.faculty_code);
}
},
I'm coding for the function to see the Faculty's details and it shows number of majors of that faculty. I don't know how to count array majors with v-if and v-for. Please help me fix that. Many thanks.
模板标签
<tr>
<td>Sumary:
<strong v-for="major in majors">
<strong v-if="form.faculty_code==majors.major_faculty">
{{ major }}
</strong>
</strong>
</td>
</tr>
脚本标签
data() {
return {
faculties:[],
majors:[],
form: new Form({
faculty_id:'',
faculty_code:'',
faculty_name:'',
faculty_status: '',
}),
};
},
mounted() {
this.fetchMajors();
this.fetchFaculties();
},
methods: {
fetchFaculties(page_url) {
let vm = this;
page_url = '../../api/admin/edu-faculty/faculty/'+this.currentEntries+'?page='+this.pagination.current_page;
fetch(page_url)
.then(res => res.json())
.then(res => {
this.faculties = res.data;
this.pagination = res.meta;
})
.catch(err => console.log(err));
},
fetchMajors(page_url) {
let vm = this;
page_url = '../../api/admin/edu-major/chuyen-nganh/major';
fetch(page_url)
.then(res => res.json())
.then(res => {
this.majors = res.data;
})
.catch(err => console.log(err));
},
}
要仅获取具有给定教员代码的专业数量,您可以在 mounted() 函数中使用
this.total.majors = 0;
this.majors.forEach((element) => {
element.major_faculty == this.faculty_code ? this.total_majors += 1 : ""
});
感谢观看和帮助我。我找到了解决方案。
模板标签
<tr>
<td>Sumary:
<strong>
{{ countA.length }}
</strong>
</td>
脚本标签
computed: {
countA() {
return this.majors.filter(major => major.major_faculty==this.form.faculty_code);
}
},