Можно ли получить объект из twig
массива зная, что индекс является javascript
переменнойSymfony массив доступ 2 веточки Javascript индекс
Mycontroller
public function showContactModalAction($iduser, $profil) {
$em = $this->getDoctrine()->getEntityManager();
$contacts = $em->getRepository("LeymaxContactBundle:User")->findBy(array('accesslevel' => 'arch'));
return $this->render('LeymaxContactBundle:Default:contactModal.html.twig', array('contacts' => $contacts));
}
MyTwig
$(".fils_zone_livre").on('click', function() {
var index=3;
var contacts = '{{contacts[index]}}';
});
и я попытался также:
var contactArray = '{{contacts|json_encode}}';
, но я получаю эту réponse:
[{},{},{},{},{},{}]
как пустой массив
Кажется, что вы ищете сериализатор объектов вместо 'json_encode'. Что относительно [** jms/serializer **] (https://github.com/schmittjoh/serializer)? – Touki