I am having trouble getting observable data to update/refresh on multiple select's dynamically simultaneously.
When rendering two+ select's with a filter displaying only those option's that are NOT selected in another select. Thus, if an option is selected in one select that same option should not appear in the other select's.
...on initial page load, the options are filtered correctly.
...on select change, the options do not re-filter correctly, I think because the options are filtered before the data value is updated (but I'm not sure they would all refresh anyway).
{^{for selectedVals ~selectedVals=selectedVals ~listVals=listVals}}
<select data-link="id">
{^{for ~catFilter(id, ~listVals, ~selectedVals)}}
<option data-link="value{:id} {:category}"></option>
{{/for}}
</select>
{{/for}}
$.views.helpers({
catFilter: function(id, listVals, selectedVals) {
return listVals.filter(item1 =>
!selectedVals.some(item2 => (item2.id) === item1.id && item1.id !== id));
}
})
I'm not quite sure the best approach to this and have tried using the built in filter=... mapDepends="id", convertBack...with little success.
Now I am listening for changes observably and refreshing the array...but It's not working (not sure if I am doing this right).
$(data[0].selectedVals).on("propertyChange", changeHandler)
function changeHandler(ev, eventArgs) {
$.observable(data[0].selectedVals).refresh(data[0].selectedVals)
}
Here is a demo: https://jsfiddle.net/alnico/tr6wfn13/
Any help/insight would be appreciated.