如何在JavaScript解释中循环查看This.questionnaire.Profile的对象(1到1)每次点击(我在论坛上找不到)

问题描述 投票:0回答:1

我创建问题组,问题的部分在This.question = {p1:{...},p2:{...},p3:{...},p4:{...}, p5:{...}等。 。 (多得多)

每次我点击(按钮)从P1到下一篇文章我怎么办... click => next article =>下篇文章(尽可能多的问题)(不需要对象内部只是元素传递)

我尝试:但它告诉我p2:

for(var question in this.questionnaire.Profil["p2"]){
   this.current=this.questionnaire.Profil["p2"][question];
   console.log(question, " -> " + this.questionnaire.Profil);
   break;
}
javascript html
1个回答
0
投票

你也可以使用profileObject.valuesforEachs上创建一个循环

Object.keys( this.questionnaire.Profil ).forEach( function( profileKey ){
   var profile = this.questionnaire.Profil[ profileKey ];
   for(var question of profile ){ //also observe of instead in
      this.current=question;
      console.log( question );
   }   
});

每次我点击(按钮)从P1到下一篇文章,我该怎么做

因此,当单击按钮时,获取下一个配置文件

var currentProfile = "p2";
var allProfiles = Object.keys( this.questionnaire.Profil );
var currentProfileIndex = allProfiles.indexOf( currentProfile );

并获得下一个配置文件

if ( currentProfileIndex < allProfiles.length - 1 )
{
   var nextProfile = allProfiles[ currentProfileIndex + 1 ];
} 
© www.soinside.com 2019 - 2024. All rights reserved.