Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
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.

Template tag

<tr>
    <td>Sumary: 
        <strong v-for="major in majors">
            <strong v-if="form.faculty_code==majors.major_faculty">
             {{ major }}
            </strong>
        </strong>
    </td>
</tr>

Script tag

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));
    },
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

To only get the amount of majors with the given faculty code you can use in your mounted() function

this.total.majors = 0;
this.majors.forEach((element) => {
    element.major_faculty == this.faculty_code ? this.total_majors += 1  : ""
});
about 4 years ago · Juan Pablo Isaza Relatório

0

Thanks for watching and help me. I've found the solution for this.

Template tag

<tr>
<td>Sumary: 
    <strong>
        {{ countA.length }}
    </strong>
</td>

Script tag

computed: {
        countA() {
            return this.majors.filter(major => major.major_faculty==this.form.faculty_code);
        }
    },
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda