I have a category drop down list which controls a sub category drop down list. I want to hide the sub categories drop down list if the sub category array is empty for the selected category.
Sample code below:
<script>
self.categories = ko.observableArray([
{"name": "top 1", "subcategories":[
{"name": "sub 1"},
{"name": "sub 2"}
]},
{"name": "top 2", "subcategories":[]}
]);
self.selected_category = ko.observable();
self.selected_sub_category = ko.obserable();
</script>
<div>
<select data-bind="options: categories, optionsText: "name", optionsCaption: "Select", value: selected_category"></select>
</div>
<div data-bind="with:selected_category">
<select data-bind="options: subcategories, optionsText: "name", optionsCaption: "Select", value: selected_sub_category"></select>
</div>