Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knockout.js change dropdown possible values based on another dropdown

I have the following problem in Knockout.JS:

Let's suppose that I have an observable array of objects, rendered with the help of a template. Each one of them has two observable properties A and B. Both of these properties take their values from dropdowns (select/options binding).

My problem is that when the selected value of A changes for one object I also want to change the available (and selected) values of B for that specific object. I can't seem to find how this is done using knockout.

I could solve the problem using Javascript or Jquery to assign handlers to the onchange event of dropdown A and change the dropdown options of B manually - however I really don't want to pollute my design with that :(

So please answer me using only knockout's tools...

Thanks !

like image 779
Serafeim Avatar asked Nov 02 '11 08:11

Serafeim


1 Answers

Take a look at the "Cart editor example" over at the Knockoutjs website. It includes an example of populating one combo box based on a parent combo box.

http://knockoutjs.com/examples/cartEditor.html

Maybe this helps?

like image 151
Mark Robinson Avatar answered Sep 29 '22 22:09

Mark Robinson