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

123
Visualizações
Have trouble getting the toggle status from api & check it with status data

I have a toggle button with titles that is setting data to send to server.

And it is getting api data like what it is posted to server. I want to check the if there is a similar item id in api data with rules then get its status and replace it with what it is right now. But i get this error changedStatus is not defined I would appreciate if someone can help me with it.

Link to my code in sandbox https://codesandbox.io/s/vuex-todo-list-forked-4kui26

    <input type="checkbox" v-model="Rule.params.value" />

     Rules: [
    {
      item_id: 144,
      title: "_00_Init_Initialization",
      params: {
        value: false,
      },
    },
    {
      item_id: 145,
      title: "_Init_AppsInitialization",
      params: {
        value: false,
      },
    },
    {
      item_id: 146,
      title: "_02_Global_Generic",
      params: {
        value: false,
      },
    },
    {
      item_id: 147,
      title: "_02_Global_Generic",
      params: {
        value: false,
      },
    },
    {
      item_id: 148,
      title: "02_Global_Generic",
      params: {
        value: false,
      },
    },
    {
      item_id: 149,
      title: "Global_Generic",
      params: {
        value: false,
      },
    },
  ],
  apiData: [
    {
      item_id: 144,
      params: {
        value: true,
      },
    },
    {
      item_id: 145,
      params: {
        value: false,
      },
    },
    {
      item_id: 146,
      params: {
        value: true,
      },
    },
    {
      item_id: 147,
      params: {
        value: true,
      },
    },
    {
      item_id: 148,
      params: {
        value: false,
      },
    },
    {
      item_id: 149,
      params: {
        value: false,
      },
    },
  ],

in methods

 mounted() {
   console.log("mounted");
   this.checkStatus();
  },
 methods: {
   checkStatus() {
     this.Rules.map((rule) => {
     this.apiData.map((data) => {
      const status = this.apiData.find(
        (data) => rule.item_id == data.item_id
      );
      if (status.params.value == true) {
        const changedStatus = this.Rules.find(
          (data) => status.item_id == data.item_id
        );
        changedStatus.params.value = true
      } else {
        changedStatus.params.value = false
      }
    });
  });
},
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try to define changedStatus outside of the condition:

methods: {
  checkStatus() {
    this.Rules.map((rule) => {
    this.apiData.map((data) => {
    const status = this.apiData.find(
      (data) => rule.item_id == data.item_id
    );
    const changedStatus = this.Rules.find(
      (data) => status.item_id == data.item_id
    );
    status.params.value == true ? 
      changedStatus.params.value = true : 
      changedStatus.params.value = false
    }
  });
});
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