How to loop over an array in data()
P粉038161873
P粉038161873 2024-03-30 23:48:57
0
1
453

I want to iterate an array in javascript inside vue.

I'm using a vertex graph. I want to iterate data[] based on the number of series (Y_Data_length).

I want to change the code

data() {
      return {
        Y_Data_length: null,
        Options: {
          xaxis: {
            categories: [],
          },
        },
        Series_1: [{
          name: "",
          data: [],
        }],

        Series_2: [{
            name: "",
            data: [],
          },
          {
            name: "",
            data: [],
          }
        ],

        Series_3: [{
            name: "",
            data: [],
          },
          {
            name: "",
            data: [],
          },
          {
            name: "",
            data: [],
          }
        ],
      };
    },

Form it.

data() {
      return {
        Y_Data_length: null,
        Options: {
          xaxis: {
            categories: [],
          },
        },
        Series: [
          {name:"", data: []}
        ],
      };
    },

For reference only, Y_Data_length is:

const A = this.chart[0].data
this.Y_Data_length = Object.keys(A).length

P粉038161873
P粉038161873

reply all(1)
P粉434996845

I'm not sure if I understand your question correctly, but if you want to get an array of data from a specific series, you can use Vue "compute" to use Y_Data_length as an array The index automatically gets the correct series.data. Whenever Y_Data_length changes, this.currentSeriesData is also updated.

export default {
  data () {
    return {
      Y_Data_length: null,
      Options: {
        xaxis: {
          categories: [],
        },
      },
      Series: [
        { name:"series1", data: [] },
        { name:"series2", data: [] },
        { name:"series3", data: [] },
      ],
    };
  },
  computed: {
    currentSeriesData() {
       const currentSeries = this.Series[this.Y_Data_length]
       if (currentSeries) {
         return currentSeries.data
       }
       return []
    }
  }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!