I'm attempting to get the list of selectedJobs below to be a dataSource for the kendoComboBox below. However, the values of the list aren't loading and I'm not getting an error and so I'm unsure of what's wrong. Is what I'm trying possible? Can I not use a ko.pureComputed() returned list as a dataSource? Also, the jobid isn't being recognized as a field for dataValueField even though the selectedJobs has this field. Thank you!
pageModel.newServiceModel.selectedJobs = ko.pureComputed(function () {
return pageModel.newServiceModel.selectedAccount() ? pageModel.newServiceModel.selectedAccount().jobs : null;
});
var source = new kendo.data.DataSource(pageModel.newServiceModel.selectedJobs);
$("#newServiceJobs").kendoComboBox({
placeholder: "Select One",
filter: "contains",
suggest: true,
change: pageModel.newServiceModel.JobSelectionChange,
dataSource: source,
//dataValueField: jobid,
dataTextField: name
});
Here are a couple of ways to fix up your existing code:
pageModel.newServiceModel.selectedJobs(). You can pass that directly in as thedataSourceproperty.dataValueFieldanddataTextFieldoptions expect strings (like "jobid" and "name")selectedJobscomputed changing, then you would need to subscribe to changes and update the control like:Here is a snippet that shows your scenario. Click the "Fill Selected Account" button to populate the
selectedAccountobservable.Another option, if possible, is to look at
knockout-kendothat will give you some basic bindings to Kendo UI from Knockout like: http://kendo-labs.github.io/knockout-kendo/web/ComboBox.html. The library handles keeping the control and view model in sync with each other and avoids you manually having to manage the kendo controls via jQuery.