0

The function work till the first debugging point and then finishes, it does not execute or loop? What Am I doing wrong here, any help is appreciated?

methods: {
    changeData(data) {
      this.data = data;
      this.data_to_show = this.data.data;
      this.source = this.data.source;
      this.database = this.data.database;
      // eslint-disable-next-line
      this.all_data = Object.values(this.data_to_show)[0];
      debugger;
      for (let i = 0; i < this.all_data.length; i += 1) {
        if (i % 2 === 0) {
          this.even_data_to_show.push({ i: this.all_data[i] });
        } else {
          this.odd_data_to_show.push({ i: this.all_data[i] });
        }
      }
      debugger;
    },
  },
4
  • 1
    Did you checked that Object.values(this.data_to_show)[0] returns an array? Commented Jul 31, 2020 at 9:48
  • yes it does, I use it for rendering. Commented Jul 31, 2020 at 10:05
  • When paused in the debugger try checking the value of this.all_data.length. Commented Jul 31, 2020 at 10:08
  • 1
    Does this answer your question? For loop inside a method using Vuejs Commented Aug 1, 2020 at 20:10

2 Answers 2

0

i think Object.values(this.data_to_show)[0],gives object. So, this.all_data.length will gives you undefined length. So, check once.

Sign up to request clarification or add additional context in comments.

Comments

-1

Why not try by key in v-loops for Vuejs.

Basic example below:- so it would be v-for...but do not use V-if

v-for='product in products'>

1 Comment

this is the buisness changes, not a view/template change. So, use of v-for is not correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.