Javascript 如何在我的视图中显示所有问题以及他们自己的选择?

Javascript 如何在我的视图中显示所有问题以及他们自己的选择?,javascript,jquery,arrays,Javascript,Jquery,Arrays,我有这个响应数组 [ { "id":16, "question":"Who is this message for?", "duration":60, "choices":[ { "id":61, "question_id":16,

我有这个响应数组

[
   {
      "id":16,
      "question":"Who is this message for?",
      "duration":60,
      "choices":[
         {
            "id":61,
            "question_id":16,
            "choice":"guests"
         },
         {
            "id":62,
            "question_id":16,
            "choice":"Eskaya"
         },
         {
            "id":63,
            "question_id":16,
            "choice":"local artists"
         },
         {
            "id":64,
            "question_id":16,
            "choice":"conference attendees"
         }
      ]
   },
   {
      "id":17,
      "question":"What is displayed in the lobby? ",
      "duration":60,
      "choices":[
         {
            "id":65,
            "question_id":17,
            "choice":"plush furniture"
         },
         {
            "id":66,
            "question_id":17,
            "choice":"the 24-hour restaurant"
         },
         {
            "id":67,
            "question_id":17,
            "choice":"the main conference rooms"
         },
         {
            "id":68,
            "question_id":17,
            "choice":"art from various local artists "
         }
      ]
   },
   {
      "id":18,
      "question":"What type of establishment is Eskaya?",
      "duration":60,
      "choices":[
         {
            "id":69,
            "question_id":18,
            "choice":"a hotel"
         },
         {
            "id":70,
            "question_id":18,
            "choice":"a pool area"
         },
         {
            "id":71,
            "question_id":18,
            "choice":"a restaurant"
         },
         {
            "id":72,
            "question_id":18,
            "choice":"a conference center"
         }
      ]
   }
]
我想在我的视图上显示它,如下所示:

1.Who is this message for?
  guests
  Eskaya
  local artists
  conference attendees

2.What is displayed in the lobby? 
  plush furniture
  the 24-hour restaurant
  the main conference rooms
  art from various local artists
差不多吧

下面是我目前拥有的代码和输出

var问题列表=”;
var radioChoices='';
对于(var i=0;i'+(i+1)+“+”+scenario_question[0]。问题[i]。问题;
对于(var x=0;x


在当前代码中,您在两个不同的变量中添加了
htmls
,这就是为什么结果是分开的。相反,您可以在一个变量中附加
divs
,并根据该变量修改代码

演示代码

var问题列表=”;
风险值情景\问题=[{
“id”:16,
“问题”:“此消息是给谁的?”,
“期限”:60,
“选择”:[{
“id”:61,
“问题编号”:16,
“选择”:“客人”
},
{
“id”:62,
“问题编号”:16,
“选择”:“Eskaya”
},
{
“id”:63,
“问题编号”:16,
“选择”:“本地艺术家”
},
{
“id”:64,
“问题编号”:16,
“选择”:“与会者”
}
]
},
{
“id”:17,
“问题”:“大厅里展示了什么?”,
“期限”:60,
“选择”:[{
“id”:65,
“问题编号”:17,
“选择”:“毛绒家具”
},
{
“id”:66,
“问题编号”:17,
“选择”:“24小时餐厅”
},
{
“id”:67,
“问题编号”:17,
“选择”:“主要会议室”
},
{
“id”:68,
“问题编号”:17,
“选择”:“来自不同本地艺术家的艺术”
}
]
},
{
“id”:18,
“问题”:“Eskaya是什么类型的机构?”,
“期限”:60,
“选择”:[{
“id”:69,
“问题编号”:18,
“选择”:“酒店”
},
{
“id”:70,
“问题编号”:18,
“选择”:“游泳池区域”
},
{
“id”:71,
“问题编号”:18,
“选择”:“餐厅”
},
{
“id”:72,
“问题编号”:18,
“选择”:“会议中心”
}
]
}
]
//循环通过json数组
$(方案\问题)。每个(函数(索引、值){
//附加值(问题)
问题列表+=''+(索引+1)+'+''+value.questions
//创建div
问题列表+=''
var计数=指数+1;
$(value.choices)。每个(函数(索引、值){
//附加选项
问题列表+=''+value.choice+'
'; }) //关闭div 问题列表+='' }) $('.listing\u question\u scenario').html(问题列表)
在当前代码中,您在两个不同的变量中添加了
htmls
,这就是为什么结果是分开的。相反,您可以在一个变量中附加
divs
,并根据该变量修改代码

演示代码

var问题列表=”;
风险值情景\问题=[{
“id”:16,
“问题”:“此消息是给谁的?”,
“期限”:60,
“选择”:[{
“id”:61,
“问题编号”:16,
“选择”:“客人”
},
{
“id”:62,
“问题编号”:16,
“选择”:“Eskaya”
},
{
“id”:63,
“问题编号”:16,
“选择”:“本地艺术家”
},
{
“id”:64,
“问题编号”:16,
“选择”:“与会者”
}
]
},
{
“id”:17,
“问题”:“大厅里展示了什么?”,
“期限”:60,
“选择”:[{
“id”:65,
“问题编号”:17,
“选择”:“毛绒家具”
},
{
“id”:66,
“问题编号”:17,
“选择”:“24小时餐厅”
},
{
“id”:67,
“问题编号”:17,
“选择”:“主要会议室”
},
{
“id”:68,
“问题编号”:17,
“选择”:“来自不同本地艺术家的艺术”
}
]
},
{
“id”:18,
“问题”:“Eskaya是什么类型的机构?”,
“期限”:60,
“选择”:[{
“id”:69,
“问题编号”:18,
“选择”:“酒店”
},
{
“id”:70,
“问题编号”:18,
“选择”:“游泳池区域”
},
{
“id”:71,
“问题编号”:18,
“选择”:“餐厅”
},
{
“id”:72,
“问题编号”:18,
“选择”:“会议中心”
}
]
}
]
//循环通过json数组
$(方案\问题)。每个(函数(索引、值){
//附加值(问题)
问题列表+=''+(索引+1)+'+''+value.questions
//创建div
问题列表+=''
var计数=指数+1;
$(value.choices)。每个(函数(索引、值){
//附加选项
问题列表+=''+value.choice+'
'; }) //关闭div 问题列表+='' }) $('.listing\u question\u scenario').html(问题列表)

var s=[{
“id”:16,
“问题”:“此消息是给谁的?”,
“期限”:60,
“选择”:[{
“id”:61,
“问题编号”:16,
“选择”:“客人”
},
{
“id”:62,
“问题编号”:16,
“选择”:“Eskaya”
},
{
“id”:63,
“问题编号”:16,
“选择”:“本地艺术家”
},
{
“id”:64,
“问题编号”:16,
“选择”:“与会者”