Answer the question
In order to leave comments, you need to log in
How to loop through json array using jQuery?
Greetings, friends! I need your help! There is a PHP array obtained from the database and the X-editable jQuery plugin:
$('.options').editable({
value: [2, 3],
source: [
{value: 1, text: 'option1'},
{value: 2, text: 'option2'},
{value: 3, text: 'option3'}
]
});
$m = Array (
[20] => Array
(
[value] => b12
[text] => Сушить исключительно в тени
)
[21] => Array
(
[value] => c1
[text] => Разрешена химчистка
)
[22] => Array
(
[value] => c2
[text] => Химчистка запрещена
)
[23] => Array
(
[value] => c3
[text] => Разрешено отбеливание
)
);
foreach ($careInfo as $item) {
$care['value'] = $item['care_key'];
$care['text'] = $item['care_desc'];
}
$('.options').editable({
value: [2, 3],
source: [<?php echo json_encode($care);?>]
});
Array
(
[value] => d6
[text] => Не отпаривать
)
Answer the question
In order to leave comments, you need to log in
I don't know about jquery, but:
for (var key in array) {
var value = array[key];
// console.log('key: ', key, 'value: ', value);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question