I'm struggling to retrieve model objects from my view model. It seems like a JavaScript/KnockoutJS familiarity issue, so any guidance is welcomed. Here is the code snippet:
<!-- VIEW -->
<select data-bind="options: allTypes,
optionsCaption: 'Choose...',
value: chosenType"></select>
<div data-bind="text: chosenType"></div>
<div data-bind="text: chosenValues"></div> <!-- << This line not functioning properly -->
<script type="text/javascript">
/*-- VIEW MODEL --*/
function ViewModel() {
this.chosenType=ko.observable();
this.chosenValues=allValues[this.chosenType]; // <-- Issue here?
}
/*-- MODEL --*/
var allTypes=["Animals","Plants","Minerals"];
var allValues={
"Animals":["Pig","Big pig","Owl"],
"Plants":["Aloe","Fern"],
"Minerals":["Bauxite","Chromite"]
};
ko.applyBindings(new ViewModel());
</script>
The problem may lie in how this.chosenValues is being declared. Appreciate your assistance.