Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!