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

135
Visualizações
Vue.js + Creating async contructor Class and accessing the data

I am a newbie and need help. I have created a class and i want to initialize my data property 'Filters' on created function with the value returned from the constructor of the class 'Filters' However as i am calling an async webapi it does not return anything into my property. How can i achieve this using class

<script>
export default {
 data() {
  return {
  Filters : [];
};
},
methods: {},
created () {
   this.Filters = new Filters(); // returns promise pending
}
};
class Filters
{
    constructor()
    {
        this.filters = this.loadFilters();
    }

    async loadFilters ()
    {
        const query = `?$select=*&$filter=_new_table_value eq ${window.parent.Xrm.Page.data.entity.getId().replace(/[{}]/g, "")}&$orderby=ice_name asc`;
        var result = await window.parent.Xrm.WebApi.retrieveMultipleRecords('ice_filterstable', query);
        console.log(result); // this does return values 
        return result;
    }
}

enter image description here

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

First, you shouldn't assign an async operation on the class constructor, it would be better to use loadFilters async function directly.

class Filters
{
constructor() {}

async loadFilters ()
{
    const query = `?$select=*&$filter=_new_table_value eq ${window.parent.Xrm.Page.data.entity.getId().replace(/[{}]/g, "")}&$orderby=ice_name asc`;
    var result = await window.parent.Xrm.WebApi.retrieveMultipleRecords('ice_filterstable', query);
    console.log(result); // this does return values 
    return result;
}
}

And then in the created lifecycle, you can execute the loadFilters function.

async created () {
    const filters = new Filters(); // returns promise pending
    this.Filters = await filters.loadFilters()
}
about 4 years ago · Santiago Gelvez 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