Reputation: 2354
I have two drop down lists. Based on the selected value of the first drop down list I need to populate the second drop downlist..
My html code:
<select class="form-control" data-bind="options: $root.schemas, optionsText: 'schema', value: selschema"></select>
<!-- ko switch: selschema -->
<!-- ko case: ['Test', 'Another Test'] -->
<select class="form-control" data-bind="options: $root.testschemas, optionsText: 'schema', value: selschematest"></select>
<!-- /ko -->
<!-- ko case: $else -->
<select class="form-control" data-bind="options: $root.othertestschemas, optionsText: 'schema', value: selschematest"></select>
<!-- /ko -->
<!-- /ko -->
My js code
function TestViewModel() {
var self = this;
self.selschema=ko.observable();
self.selschematest=ko.observable();
self.schemas = ko.observableArray([{ "schema": "Test" }, { "schema": "Another Test" }, { "schema": "Other Test" }]);
self.testschemas = ko.observableArray([{ "schema": "Test1" }, { "schema": "Test2" }]);
self.othertestschemas = ko.observableArray([{ "schema": "other Test1" }, { "schema": "other Test2" }]);
}
ko.applyBindings(new TestViewModel());
I'm trying to use knockout-switch-case by MichaelBest but its always going inside the else statement..
Any help is sincerely appreciated
Thanks
Upvotes: 0
Views: 373