i am wondering if there is any possiblity to get the select options values from a function, which is invoked with a parameter.
for example:
my markup
<select data-bind="options: $root.getOptions('one', $data.ID), optionsCaption: '...', optionsText:'Txt', optionsValue:'ID'">
my js
self.getSelectionData = function (type, param) {
if (type == "one") {
var idParam = new Object();
idParam.id = param();
$.getJSON('/MyController/MyGetAction', idParam, function (result) {
var r = ko.mapping.fromJS(r);
return r;
});
}
};
the “r” does contain the correct data, but no data is displayed in the select.
i tried several things but couldn’t make it. any idea (or hint that i’m doing it wrong) ?
You should put
returnbefore$.getJSONbecause yourgetSelectionDatafunction returns nothing instead of result of JSON request:Or you can define
ringetSelectionDatafunction: