带有下拉列表的 Knockout Js switch case

Knockoutjs switch case with drop downlist

我有两个下拉列表。根据第一个下拉列表的选定值,我需要填充第二个下拉列表..

我的html代码:

<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 -->

我的js代码

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());

Jsfiddle:

我正在尝试使用 knockout-switch-case by MichaelBest 但它总是在 else 语句中..

真诚感谢任何帮助

谢谢

<!-- ko switch: selschema().schema -->

解决了问题.. 将 <pre data-bind="text: ko.toJSON($data, null, 2)"></pre> 添加到 html 给我指明了方向..

jsfiddle: