This is a migrated thread and some comments may be shown as answers.

Binding Data to combobox after ajax call using mvvm

1 Answer 239 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Dinesh
Top achievements
Rank 1
Dinesh asked on 08 Apr 2013, 01:56 PM
Hi,

I am using MVVM Framework

var indexViewModel = kendo.observable({
StatesList: statesList,
CountriesList: countriesList,
SelectedCountry: null
});


kendo.bind($("body"), indexViewModel);

Calling an ajax call in document ready function

$("document").ready(function () {
GetBaseInfo();
}

function GetBaseInfo()
{
$.ajax({
url: "http://localhost:64283/DRRService.svc/GetBaseData",
dataType: "jsonp",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data == null) {
alert("No Data Available");
}
else {

statesList = data.statesList;
countriesList = data.countriesList;
 
$("#countriesCombo").data("kendoComboBox").dataSource.data = countriesList;
$("#countriesCombo").data("kendoComboBox").refresh();

 
}
}
});

}
Mu UI Part is this

<select id="countriesCombo" data-role="combobox" data-text-field="Value"
data-bind="source:CountriesList" />

The data is not getting refreshed. Can you please provide the solution to this

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 10 Apr 2013, 10:51 AM
Hello Dinesh,

You should set the new arrays to the viewModel e.g.
 

indexViewModel.set("StatesList",  data.statesList);
Kind regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
ComboBox
Asked by
Dinesh
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or