[英]How can i each a Json response with Jquery?
Good morning , I am programming with Symfony . 早上好,我正在用Symfony编程。 This is my Action :
这是我的动作:
public function selectcarsmonitorsAction($date) {
$cars = array();
$users= array();
// Liste des voitures
$cars = $em->getRepository('ParcAutoBundle:Car')->FindAllCarsNotINCalendar($location, $date);
// Liste des moniteurs
$users= $em->getRepository('AuthenticationBundle:User')->FindAllUsersNotINCalendar($location, $date);
foreach ($cars as $car) {
$cars[] = $car->getId() . " " . $car->getMark() . " " . $car->getRegistrationnumber();
}
foreach ($users as $user) {
$monitors[] = $user->getId() . " " . $user->getFirstname() . " " . $monitor->getLastname();
}
$response = new JsonResponse();
$response->setData(array('cars' => $cars, 'users' => $users));
return $response;
}
First : I don't know what's the underlined? 首先:不知道下划线是什么? Strange
奇怪
Second : I want to put this in a select and option ( a Select for cars and a select for Users). 第二:我想把它放在一个选择和选项中(一个“选择汽车”和一个“用户选择”)。
thank you for your helps . 谢谢您的帮助。
EDIT 1 : 编辑1:
How can i each this with JQUERY ?? 我怎样才能与JQUERY一起使用?
second: 第二:
var select = $('#selectTag');
$.ajax({
url: 'your_api',
success: function(data) {
var cars = data.cars;
$.each(cars, function(index, item) {
select.append($('<option>'), {
value: xxx,
text: xxx
}));
});
},
error: function(xhr, status, err) {
console.error(url, status, err.toString());
}
});
in the each i putted Json.parse() : 在每个我放入Json.parse()中:
$.each(JSON.parse(cars), function (i, v) {
selectcars += '<option value=' + v.id + '>' + v.mark + ' ' + v.registrationnumber + '</option>';
});
$('#cars').append(selectcars);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.