I am trying to create a filtered select list of sources based on the media selected. I know the method I used below filters but does not display the list correctly. I am half asleep and trying to correct this and need some input from someone. :-) Cheers!
let types = [
{
"id": 1,
"media": "TV",
"source": "wkbw"
},
{
"id": 2,
"media": "TV",
"source": "wffo"
},
{
"id": 3,
"media": "TV",
"source": "wtrw"
},
{
"id": 8,
"media": "Radio",
"source": "wrqa"
},
{
"id": 9,
"media": "Radio",
"source": "wuqa"
},
{
"id": 10,
"media": "Radio",
"source": "wzzt"
}
]
$("#type").change(function() {
$("#results").empty();
selected = $("#type").val();
for (var i = 0; i < types.length; i++) {
// some kind of filter source by selected the one below isn't quite right
// $("#results").append("<option value='" + types[i].source + "'>" + types[i].source + "</option>");
source = types.filter(types => types.media === selected).map(d => d.source).join('');
$("#results").append("<option value='" + source + "'>" + source + "</option>");
}
});
Here is my fiddle: https://jsfiddle.net/simplymarkb/sk0rdf2j/31/