I want to access an array of data from my twig in my javascript but it never gets the full array.
I have a controller that returns an array of objects that I'm using in my twig, here is an example of the objects stored :
Now, I want to access it in my javascript, I tried a lot of things but ended up with using data in my div : (following that https://symfony.com/doc/current/frontend/encore/server-data.html?fbclid=IwAR2BHWMl-OJSytkfbNgaNUFRefC85bTPw63ymvuC9Q4zPlKxZZoKZ7dvH9E)
<div class="table_congesService" data-conges-service="{{congesService|json_encode|e('html_attr') }}">
And
<script>
document.addEventListener('DOMContentLoaded', function() {
var tableCongesService = document.querySelector('.table_congesService');
var listCongesService = tableCongesService.dataset.congesService;
console.log(listCongesService);
});
</script>
However, instead of having the full structure, I only have the id when I'm displaying the result with the console.log:
What am I missing? I'm new to web and can't find what is wrong. Does it have something with the structure of my data before the encode? Or an option that I should use?