最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Knockout.js change dropdown possible values based on another dropdown - Stack Overflow

programmeradmin3浏览0评论

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 !

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 !

Share Improve this question asked Nov 2, 2011 at 8:28 SerafeimSerafeim 15.1k15 gold badges95 silver badges136 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 16

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?

发布评论

评论列表(0)

  1. 暂无评论