Answer the question
In order to leave comments, you need to log in
How to parse JSON and use its values in DOM?
We have JSON:
newdate = {
2018:{
7:[1, 2],
8:[10,15,21]
},
2019:{
1:[2,3],
11:[4]
}
};
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table id="calendar" border="0" cellspacing="0" cellpadding="1">
<thead>
<tr>
<td><b>‹</b>
</td>
<td colspan="5" data-month="7" data-year="2018">Август 2018</td>
<td><b>›</b>
</td>
</tr>
<tr>
<td>Пн</td>
<td>Вт</td>
<td>Ср</td>
<td>Чт</td>
<td>Пт</td>
<td>Сб</td>
<td>Вс</td>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>
<tr>
<td>13</td>
<td>14</td>
<td class="today">15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
</tr>
<tr>
<td>20</td>
<td>21</td>
<td>22</td>
<td>23</td>
<td>24</td>
<td>25</td>
<td>26</td>
</tr>
<tr>
<td>27</td>
<td>28</td>
<td>29</td>
<td>30</td>
<td>31</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
Answer the question
In order to leave comments, you need to log in
Decision:
$("#calendar td").each(function () {
if (parseInt($(this).text())) {
let yearMonth = sheduleDate[$('#calendar td[data-year]').attr('data-year')][$('#calendar td[data-month]').attr('data-month')];
// console.log(yearMonth)
if (yearMonth) {
if (yearMonth.indexOf(parseInt($(this).text())) !== -1) {
$(this).addClass('scheduleday')
console.log(yearMonth)
}
}
}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question