Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

120
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda