Skip to main content
adicionou 11 caracteres ao conteúdo
Fonte Link
Lucas Brogni
  • 1mil
  • 6
  • 15

Opa... Dá pra fazer dessa forma:

  employees = [
    {
      id: 1,
      firstName: 'a',
      lastName: 'A',
      position: 'PA',
      chefes: [2, 3],
      compensation: '123.00'
    },
    {
      id: 2,
      firstName: 'b',
      lastName: 'B',
      position: 'PB',
      chefes: [4],
      compensation: '456.00'
    },
    {
      id: 3,
      firstName: 'c',
      lastName: 'C',
      position: 'PC',
      compensation: '789.00',
      chefes: []
    },
    {
      id: 4,
      firstName: 'd',
      lastName: 'D',
      position: 'PD',
      compensation: '1011.00',
      chefes: []
    }
  ];

  contaChefes(idInformado) {
    let totalChefes = 0;

    this.employees.map(e => {

      if (e.chefes && e.id === idInformado){
        totalChefes += e.chefes.length;

        e.chefes.forEach(r => {
          totalChefes += this.contaChefes(r);
        })
      }
    })
    return totalChefes;
  }

<dl>
    <dt>Título</dt>
    <dd>{{employee.position}}</dd>
    <dt>Compensation</dt>
    <dd>${{employee.compensation}}</dd>
    <dt>Total</dt>
    <dd> {{ contaChefes(employee.id) }} </dd>
</dl>

Opa... Dá pra fazer dessa forma:

  employees = [
    {
      id: 1,
      firstName: 'a',
      lastName: 'A',
      position: 'PA',
      chefes: [2, 3],
      compensation: '123.00'
    },
    {
      id: 2,
      firstName: 'b',
      lastName: 'B',
      position: 'PB',
      chefes: [4],
      compensation: '456.00'
    },
    {
      id: 3,
      firstName: 'c',
      lastName: 'C',
      position: 'PC',
      compensation: '789.00',
      chefes: []
    },
    {
      id: 4,
      firstName: 'd',
      lastName: 'D',
      position: 'PD',
      compensation: '1011.00',
      chefes: []
    }
  ];

  contaChefes(idInformado) {
    let totalChefes = 0;

    this.employees.map(e => {

      if (e.chefes && e.id === idInformado){
        totalChefes += e.chefes.length;

        e.chefes.forEach(r => {
          totalChefes += this.contaChefes(r);
        })
      }
    })
    return totalChefes;
  }

<dl>
    <dt>Título</dt>
    <dd>{{employee.position}}</dd>
    <dt>Compensation</dt>
    <dd>${{employee.compensation}}</dd>
    <dt>Total</dt>
    {{ contaChefes(employee.id) }}
</dl>

Opa... Dá pra fazer dessa forma:

  employees = [
    {
      id: 1,
      firstName: 'a',
      lastName: 'A',
      position: 'PA',
      chefes: [2, 3],
      compensation: '123.00'
    },
    {
      id: 2,
      firstName: 'b',
      lastName: 'B',
      position: 'PB',
      chefes: [4],
      compensation: '456.00'
    },
    {
      id: 3,
      firstName: 'c',
      lastName: 'C',
      position: 'PC',
      compensation: '789.00',
      chefes: []
    },
    {
      id: 4,
      firstName: 'd',
      lastName: 'D',
      position: 'PD',
      compensation: '1011.00',
      chefes: []
    }
  ];

  contaChefes(idInformado) {
    let totalChefes = 0;

    this.employees.map(e => {

      if (e.chefes && e.id === idInformado){
        totalChefes += e.chefes.length;

        e.chefes.forEach(r => {
          totalChefes += this.contaChefes(r);
        })
      }
    })
    return totalChefes;
  }

<dl>
    <dt>Título</dt>
    <dd>{{employee.position}}</dd>
    <dt>Compensation</dt>
    <dd>${{employee.compensation}}</dd>
    <dt>Total</dt>
    <dd> {{ contaChefes(employee.id) }} </dd>
</dl>
Fonte Link
Lucas Brogni
  • 1mil
  • 6
  • 15

Opa... Dá pra fazer dessa forma:

  employees = [
    {
      id: 1,
      firstName: 'a',
      lastName: 'A',
      position: 'PA',
      chefes: [2, 3],
      compensation: '123.00'
    },
    {
      id: 2,
      firstName: 'b',
      lastName: 'B',
      position: 'PB',
      chefes: [4],
      compensation: '456.00'
    },
    {
      id: 3,
      firstName: 'c',
      lastName: 'C',
      position: 'PC',
      compensation: '789.00',
      chefes: []
    },
    {
      id: 4,
      firstName: 'd',
      lastName: 'D',
      position: 'PD',
      compensation: '1011.00',
      chefes: []
    }
  ];

  contaChefes(idInformado) {
    let totalChefes = 0;

    this.employees.map(e => {

      if (e.chefes && e.id === idInformado){
        totalChefes += e.chefes.length;

        e.chefes.forEach(r => {
          totalChefes += this.contaChefes(r);
        })
      }
    })
    return totalChefes;
  }

<dl>
    <dt>Título</dt>
    <dd>{{employee.position}}</dd>
    <dt>Compensation</dt>
    <dd>${{employee.compensation}}</dd>
    <dt>Total</dt>
    {{ contaChefes(employee.id) }}
</dl>