我想在 vue 内的 javascript 中迭代数组。
我正在使用顶点图。我想根据系列数(Y_Data_length)迭代 data[]。
我想更改代码
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: [],
}
],
};
},
形成它。
data() {
return {
Y_Data_length: null,
Options: {
xaxis: {
categories: [],
},
},
Series: [
{name:"", data: []}
],
};
},
仅供参考,Y_Data_length 为:
const A = this.chart[0].data this.Y_Data_length = Object.keys(A).length
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我不确定是否正确理解了你的问题,但如果你想从特定系列中获取
data数组,你可以使用 Vue“计算”来使用Y_Data_length作为数组索引自动获取正确的series.data 。每当Y_Data_length发生变化时,this.currentSeriesData也会更新。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 [] } } }