javascript - About the problem that the name of the nested object in js is a variable
習慣沉默
習慣沉默 2017-06-26 10:51:55
0
1
640

I defined a nested loop in angular2 to display a form. Now I want to process the data entered by the user. The code is as follows

this.data = value;
for (var i=0;i<this.questionlist.length;i++){
    this.questionId[i]=this.questionlist[i].id;
    this.tempdata = this.questionlist[i].ans;
    for(var j=0;j<this.tempdata.length;j++){
        console.log(this.data[this.questionId[i]].(this.tempdata[j]))
    }
}

The names of each array and the arrays nested inside are the methods of obtaining the data before. Generally speaking, they are not fixed. Now I want to read out each value, so the question is, what should I do? How can I read the nested value where the last this.tempdata[j] is the name?
I’ve been thinking about it for a long time and checking it out for a long time, but I can’t find any solution_(:з ∠)_

習慣沉默
習慣沉默

reply all(1)
小葫芦

Can you write a mock of your data? It’s very abstract. Look at the data and tell everyone which one and which layer you want to get. It will be easier to understand

Is this what you want

this.data[this.questionId[i]][this.tempdata[j]]

Is this how to take the this.tempdata[j] attribute of this.questionId[i] under this.data (it is still an object here)?

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!