I have the following php array in a laravel variable called $salaries which is passed to a blade view:
array:4 [▼
2 => "£8, Per hour"
3 => "£10, Per hour"
23 => "Up to £10000, Per annum"
24 => "£10,000 - £15,000, Per annum"
]
In my blade view I have a drop which when changed, I want to load a select2 dropdown with the above options. Below is my code:
$(document).on("change", ".js-selector", function() {
var options = {!! json_encode($salaries) !!};
$("#salary_list").empty().select2({
data: options
});
})
However nothing is getting loaded into the dropdown. So I've narrowed it down to the options data for select2 not being in the correct format.
When I output options variable to console I'm getting the following object as opposed to a javascript array?
{2: "£8, Per hour", 3: "£10, Per hour", 23: "Up to £10000, Per annum", 24: "£10,000 - £15,000, Per annum"}
How do I transform the options into correct format for the select2 data?