Jquery json ma'lumotlarni tahlil qilish

this is my json:

{
"box 1": [{
    "difficulty_grade": "5a+"
}, {
    "gym": "New_gym"
}, {
    "route_author": "some author"
},]}

enter image description here

Bu mening kodim: o'zgarmaydigan groups rasmda ko'rsatilgan jsonni o'z ichiga oladi

for (var k in groups){
$p("#panel").append('<div class="flip_sector">' + k + '<div class="sect_n"></div></div>');
for (var i = 0; i"+groups[k][i]['route_author']+" | "+groups[k][i]['route_author']+"").insertAfter(".flip_sector");

Rasmdagi bu o'zgaruvchan guruhlar.

console.log(groups[k][i]['difficulty_grade']);
}
}

Header qutisi 1, quti2, ... va sloyto'pni yaratish kerak.

Bu mening chiqishim:

enter image description here

Ushbu chiqishda faqat box 1 dan birinchi ob'ekt ko'rsatiladi. Menga yordam bera olasizmi?

1
Men json qo'shib, xabarni yangilab turaman.
qo'shib qo'ydi muallif First, manba
Men json qo'shib, xabarni yangilab turaman.
qo'shib qo'ydi muallif First, manba
Men json qo'shib, xabarni yangilab turaman.
qo'shib qo'ydi muallif First, manba
Kerakli natijalar nima? Yon eslatmada, siz raw json formatini o'zgartirsangiz va savolingizni yangilab tursangiz, bu sizning o'qilishi mumkinligini oshiradi. formatlash uchun jsonlint veb-saytini sinab ko'rish.
qo'shib qo'ydi muallif Bhavik Patel, manba
Kerakli natijalar nima? Yon eslatmada, siz raw json formatini o'zgartirsangiz va savolingizni yangilab tursangiz, bu sizning o'qilishi mumkinligini oshiradi. formatlash uchun jsonlint veb-saytini sinab ko'rish.
qo'shib qo'ydi muallif Bhavik Patel, manba

6 javoblar

Ikkinchi marta noto'g'ri ishlatasiz.

for (var k in groups){
  for (var i in groups[k]){
    console.log(groups[k][i]['difficulty_grade']);
  }
}
1
qo'shib qo'ydi

Ikkinchi marta noto'g'ri ishlatasiz.

for (var k in groups){
  for (var i in groups[k]){
    console.log(groups[k][i]['difficulty_grade']);
  }
}
1
qo'shib qo'ydi

Muammoni hal qilaman. Bu kod barqaror.

var count = 0;
    for (var k in groups){

$p(".loader_sector").append('<div class="flip_sector" id="sector_id_'+count+'"><div class="header" style="padding: 6px;margin-bottom:4px;margin-left: -10px;padding-left: 13px;">' + k + '</div><div id = "container_id_'+count+'" class="container_class" style="display:none"></div></div>');
console.log(groups[k]);

for (var i = 0; i< groups[k].length; i++) {
console.log(groups[k][i]['difficulty_grade']);
$p("#container_id_"+count+"").append("<div class='pan_sect' data-count='"+count+"'><div style='margin-bottom:-33px'><div style ='position:relative;bottom:46px;left:64px;color:#009c89'>"+ groups[k][i]['route_author'] +"</div>" + "" + groups[k][i]['route_name'] + "| Grade: " + groups[k][i]['difficulty_grade'] + "| Box4" + "</div>

</div>");
}count++;

}

Problem: When I append here:

$p("#container_id_"+count+"").append("<div class='pan_sect' data-count='"+count+"'><div style='margin-bottom:-33px'><div style ='position:relative;bottom:46px;left:64px;color:#009c89'>"+ groups[k][i]['route_author'] +"</div>" + "" + groups[k][i]['route_name'] + "| Grade: " + groups[k][i]['difficulty_grade'] + "| Box4" + "</div>

</div>");

earlier I add new div with the same class. I create difficult id's using variable count and add it to $p("#container_id_"+count+"")

0
qo'shib qo'ydi

Muammoni hal qilaman. Bu kod barqaror.

var count = 0;
    for (var k in groups){

$p(".loader_sector").append('<div class="flip_sector" id="sector_id_'+count+'"><div class="header" style="padding: 6px;margin-bottom:4px;margin-left: -10px;padding-left: 13px;">' + k + '</div><div id = "container_id_'+count+'" class="container_class" style="display:none"></div></div>');
console.log(groups[k]);

for (var i = 0; i< groups[k].length; i++) {
console.log(groups[k][i]['difficulty_grade']);
$p("#container_id_"+count+"").append("<div class='pan_sect' data-count='"+count+"'><div style='margin-bottom:-33px'><div style ='position:relative;bottom:46px;left:64px;color:#009c89'>"+ groups[k][i]['route_author'] +"</div>" + "" + groups[k][i]['route_name'] + "| Grade: " + groups[k][i]['difficulty_grade'] + "| Box4" + "</div>

</div>");
}count++;

}

Problem: When I append here:

$p("#container_id_"+count+"").append("<div class='pan_sect' data-count='"+count+"'><div style='margin-bottom:-33px'><div style ='position:relative;bottom:46px;left:64px;color:#009c89'>"+ groups[k][i]['route_author'] +"</div>" + "" + groups[k][i]['route_name'] + "| Grade: " + groups[k][i]['difficulty_grade'] + "| Box4" + "</div>

</div>");

earlier I add new div with the same class. I create difficult id's using variable count and add it to $p("#container_id_"+count+"")

0
qo'shib qo'ydi

Muammoni hal qilaman. Bu kod barqaror.

var count = 0;
    for (var k in groups){

$p(".loader_sector").append('<div class="flip_sector" id="sector_id_'+count+'"><div class="header" style="padding: 6px;margin-bottom:4px;margin-left: -10px;padding-left: 13px;">' + k + '</div><div id = "container_id_'+count+'" class="container_class" style="display:none"></div></div>');
console.log(groups[k]);

for (var i = 0; i< groups[k].length; i++) {
console.log(groups[k][i]['difficulty_grade']);
$p("#container_id_"+count+"").append("<div class='pan_sect' data-count='"+count+"'><div style='margin-bottom:-33px'><div style ='position:relative;bottom:46px;left:64px;color:#009c89'>"+ groups[k][i]['route_author'] +"</div>" + "" + groups[k][i]['route_name'] + "| Grade: " + groups[k][i]['difficulty_grade'] + "| Box4" + "</div>

</div>");
}count++;

}

Problem: When I append here:

$p("#container_id_"+count+"").append("<div class='pan_sect' data-count='"+count+"'><div style='margin-bottom:-33px'><div style ='position:relative;bottom:46px;left:64px;color:#009c89'>"+ groups[k][i]['route_author'] +"</div>" + "" + groups[k][i]['route_name'] + "| Grade: " + groups[k][i]['difficulty_grade'] + "| Box4" + "</div>

</div>");

earlier I add new div with the same class. I create difficult id's using variable count and add it to $p("#container_id_"+count+"")

0
qo'shib qo'ydi

Muammoni hal qilaman. Bu kod barqaror.

var count = 0;
    for (var k in groups){

$p(".loader_sector").append('<div class="flip_sector" id="sector_id_'+count+'"><div class="header" style="padding: 6px;margin-bottom:4px;margin-left: -10px;padding-left: 13px;">' + k + '</div><div id = "container_id_'+count+'" class="container_class" style="display:none"></div></div>');
console.log(groups[k]);

for (var i = 0; i< groups[k].length; i++) {
console.log(groups[k][i]['difficulty_grade']);
$p("#container_id_"+count+"").append("<div class='pan_sect' data-count='"+count+"'><div style='margin-bottom:-33px'><div style ='position:relative;bottom:46px;left:64px;color:#009c89'>"+ groups[k][i]['route_author'] +"</div>" + "" + groups[k][i]['route_name'] + "| Grade: " + groups[k][i]['difficulty_grade'] + "| Box4" + "</div>

</div>");
}count++;

}

Problem: When I append here:

$p("#container_id_"+count+"").append("<div class='pan_sect' data-count='"+count+"'><div style='margin-bottom:-33px'><div style ='position:relative;bottom:46px;left:64px;color:#009c89'>"+ groups[k][i]['route_author'] +"</div>" + "" + groups[k][i]['route_name'] + "| Grade: " + groups[k][i]['difficulty_grade'] + "| Box4" + "</div>

</div>");

earlier I add new div with the same class. I create difficult id's using variable count and add it to $p("#container_id_"+count+"")

0
qo'shib qo'ydi
Javascript UZB
Javascript UZB
99 ishtirokchilar

@js_uzb @vuejs_uz @react_uz @nodejs_uz @angular_uz @ngTashkent @yiiframework_uz @laravel_uz @linux_uzbek @python_uz @swift_uzb —————— @uzdevgroup @UzGeeksGroup ——— @UzDev_Jobs @jobs_uzb