Most of the small partners will be working with JSON and arrays, case up
var data = {
' 2018 ': [
{
' title ': ' Case One ',
' Name ': ' Fanny1 '
},
{
' title ': ' Case One ',
' Name ': ' Fanny2 '
}
],
' 2017 ': [
{
' title ': ' Case two ',
' Name ': ' Fanny1 '
},
{
' title ': ' Case two ',
' Name ': ' Fanny2 '
}
]
}
Most of the data that is normally received from the background is in this form
1.json loop inside: for (var key in data) {}
there is a way to get the key value directly Object.keys (data)
If you want to get a separate key value Object.keys (data) [0]
2. There are many kinds of loops in an array, for example a
var arraydata = Data[key];
Arraydata.map ((Item,index) =>{
Console.log (item)//To get every data in the array
})
3. If your outer layer needs this data, we'll stitch it up
var shtml= "";
for (var key in data) {
var reportdata = Data[key];
SHTML1 + = ' <li> ';
SHTML1 + = ' <div class= ' menu_title ' ><span> ' + key + ' year </span></div> ';
SHTML1 + = ' <ul class= ' menu_content ' > ';
ReportData. Map (Item,index) =>{
SHTML1 + = ' <li attr-href= ' +item.title+ ' attr-img= ' +item.name+ ' > ' +item.title+ ' </li> ';
}
SHTML1 + = ' </ul></li> ';
}
And then render it in
Document.queryselector (". Main"). AppendChild (SHTML1);
* Attention Issues
The key value in this case is a number, the default is ascending order, you need to arrange your own
JSON, the loop case of an array