I have a project where I am using a Kendo DropDownList in the MVVM paradigm. The dropdownlist sources its data from a JavaScript array in the viewmodel and its value is bound to a property in the same viewmodel.
The problem is the dropdownlist always remains on the first item. I can choose "inactive" (the second item) and it updates viewModel.data.IsActive to "true" but the first "Active" item remains selected in the dropdown.
If you change the initial viewModel.data.IsActive to false, then upon load the second "Inactive" item is selected in the dropdown. But once I change it to "Active", it's stuck there, I can't get back to "Inactive"
What is wrong with this code? Am I missing something simple?
Thanks,
Rod Early
The viewmodel:
var viewModel = {};
viewModel.data = {};
viewModel.data.IsActive = true;
viewModel.lookupData = {};
viewModel.lookupData.status = [{
value: true,
text: "Active"
}, {
value: false,
text: "Inactive"
}];
The html:
<div class="container">
<div style="margin: 10px 0 20px 20px">
<span style="display:inline">Selected data</span>
<span data-bind="text: data.IsActive">none provided</span>
</div>
<select id="theDropdown" data-role="dropdownlist" data-bind="source: lookupData.status, value: data.IsActive" data-text-field="text" data-value-field="value" />
</div>
And the binding:
kendo.bind($(".container"), kendo.observable(viewModel));
This is all implemented in a jsFiddle
The problem is the dropdownlist always remains on the first item. I can choose "inactive" (the second item) and it updates viewModel.data.IsActive to "true" but the first "Active" item remains selected in the dropdown.
If you change the initial viewModel.data.IsActive to false, then upon load the second "Inactive" item is selected in the dropdown. But once I change it to "Active", it's stuck there, I can't get back to "Inactive"
What is wrong with this code? Am I missing something simple?
Thanks,
Rod Early
The viewmodel:
var viewModel = {};
viewModel.data = {};
viewModel.data.IsActive = true;
viewModel.lookupData = {};
viewModel.lookupData.status = [{
value: true,
text: "Active"
}, {
value: false,
text: "Inactive"
}];
The html:
<div class="container">
<div style="margin: 10px 0 20px 20px">
<span style="display:inline">Selected data</span>
<span data-bind="text: data.IsActive">none provided</span>
</div>
<select id="theDropdown" data-role="dropdownlist" data-bind="source: lookupData.status, value: data.IsActive" data-text-field="text" data-value-field="value" />
</div>
And the binding:
kendo.bind($(".container"), kendo.observable(viewModel));
This is all implemented in a jsFiddle