Цыкл с массива
Подскажите, как сделать аналогичный перебор массива цыклом только на javascript. Вот есть код на php:
foreach ($data['comments'] as $row_com) {
echo "<div class='row'>
<div class='col-sm-1'></div>
<div class='col-sm-3' id='log_com'><b>".$row_com['login_comment']."</b></div>
<div class='col-sm-8' id='data_com'><u>".$row_com['date_comment']."</u></div>
</div>
<div class='row'>
<div class='col-sm-1'></div>
<div class='col-sm-11'>
<i>".$row_com['text_comment']."</i></div>
</div><hr/ id='hr_com'>";
}
|
for(var in data) {
document.write("<div class='row'>\
<div class='col-sm-1'></div>\
<div class='col-sm-3' id='log_com'><b>" + data[i].login_comment + "</b></div>\
<div class='col-sm-8' id='data_com'><u>" + data[i].date_comment + "</u></div>\
</div>\
<div class='row'>\
<div class='col-sm-1'></div>\
<div class='col-sm-11'>\
<i>" + data[i].text_comment + "</i></div>\
</div><hr id='hr_com'>");
}
|
Спасибо за ответ! И еще один вопрос. Если у меня сервер возвращает вот такой массив:
array (size=4)
1 =>
array (size=4)
'id' => string '1' (length=1)
'text_comment' => string 'Просто комент' (length=25)
'login_comment' => string 'juramaj' (length=7)
'date_comment' => string '29.11.2014 14:23' (length=16)
2 =>
array (size=4)
'id' => string '2' (length=1)
'text_comment' => string 'Ну уж очень простой коментарий' (length=56)
'login_comment' => string 'Taras78' (length=7)
'date_comment' => string '21.12.2014 21:20' (length=16)
3 =>
array (size=4)
'id' => string '3' (length=1)
'text_comment' => string 'asdfg' (length=5)
'login_comment' => string 'juramaj' (length=7)
'date_comment' => string '22.12.2014 17:52' (length=16)
4 =>
array (size=4)
'id' => string '4' (length=1)
'text_comment' => string 'dfdghj' (length=6)
'login_comment' => string 'juramaj' (length=7)
'date_comment' => string '22.12.2014 18:06' (length=16)
то могу ли я его преобразовав в json обьект вывести с помощью того цыкла что вы мне написали в начале этой темы? Спасибо |
| Часовой пояс GMT +3, время: 15:39. |