Similar to the knockoutjs shopping cart example, I have a list of packages, and the price depends on the location. I am unable to bind the dependent select box (the locationOptions) with the view:
<select data-bind="options: packages,
optionsCaption: 'Select...',
optionsText: 'name',
value: selectedPackage">
</select>
<select data-bind="options: locationOptions,
optionsCaption: 'Select...',
optionsText: 'location',
value: selectedLocation">
</select>
<span data-bind="with: selectedPackage">
<p>You have chosen <b data-bind="text: name"></b> (<span data-bind="text: description">)</span>
In location <b data-bind="text: location"></b></p>
<p>Total is <b data-bind="text: total"></b></p>
</span>
view model:
function viewModel(packages, addons) {
this.packages = packages;
this.selectedPackage = ko.observable();
this.selectedLocation = ko.observable();
this.total = ko.computed(function(){
var x = 0;
return x;
});
}
Here is the jsfiddle http://jsfiddle.net/KN4P6/6/