I've been trying to create an dropdown tree with my json. It represents two categories with a list of products.
Here my JSON Array:
[
{
"reference":'BC-ENFANT',
"name":'Pour les Enfants',
"description":'Soins pour les enfants...',
"id":155,
"productList":[
{"id":13655,"reference":'PROD_ENFANT_01',"name":'Brushing'},
{"id":13656,"reference":'PROD_ENFANT_03',"name":'Soins'},
]
},
{
"reference":'BC-FEMME',
"name":'Pour les Femmes',
"description":'Prestations pour les femmes',"id":154,
"productList":[
{"id":13657,"reference":'PROD_ENFANT_01',"name":'Brushing'},
{"id":13658,"reference":'PROD_ENFANT_03',"name":'Soins'},
]}]
I have been only able to populate a simple select2 with those lines (Using Ajax call) :
<div class="form-group">
<label class="form-label" for="prestationCombo">Prestation</label>
<div class="input-group">
<select type="text" id="benefitList" class="form-control"></select>
</div>
</div>
$.post("BookingManager/CategoryResult",
{
shopId: shopId
},
function (data) {
console.log(data);
$('#benefitList').select2({
multiple: false,
data: data.map(c => { return c.reference }),
dropdownParent: $('#emptyEvent'),
placeholder: 'Rechercher une prestation...',
});
}
);
I have already used select2 but never find a way to get a proper solution to this problem.