I am having a day with knockout. Here is my simplified VM:
function UserRecruitingViewModel(apiBaseUrl, userId) {
var self = this;
self.orgs = ko.observableArray();
//ddl org view switcher stuff
self.orgDdl = ko.observableArray();
self.selectedOrg = ko.observable();
var DropdownOrg = function (name, orgId) {
this.name = name;
this.orgId = orgId;
};
//...snip ajax get to pull data...//
}
Note I have this line in there:
self.selectedOrg = ko.observable();
On my page I have this drop down list:
<select
data-bind="options: $root.orgDdl, optionsText: 'name', optionsValue: $root.selectedOrg">
</select>
For easier reading, the data-bind values:
data-bind="
options: $root.orgDdl,
optionsText: 'name',
optionsValue: $root.selectedOrg"
This is not working. If I have my select element like without the optionsValue binding in there it will bind the list with the value I got from the GET request.
I am getting an error in my console saying:
Unable to process binding "text: function (){return selectedOrg() }"
Message: selectedOrg is not defined
I am confused since I do have the selectedOrg observable set on my VM.