淘汰赛。基于另一个下拉列表,js更改了可能的值。

时间:2022-12-03 12:54:22

I have the following problem in Knockout.JS:

我在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).

假设我有一个可观察到的对象数组,在模板的帮助下呈现。每个属性都有两个可观察到的属性A和b。

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.

我的问题是,当一个对象的一个更改的选择值时,我还想要为该特定对象更改B的可用(和选定的)值。我似乎找不到这是怎么用淘汰赛。

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 :(

我可以用Javascript或Jquery来解决这个问题,将处理程序分配给dropdown A的onchange事件,并手动更改B的下拉选项——但是我真的不想用它来污染我的设计:(

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

所以,请用knockout的工具回答我……

Thanks !

谢谢!

1 个解决方案

#1


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.

看看Knockoutjs网站上的“Cart编辑器示例”。它包括一个基于父组合框填充一个组合框的示例。

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

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

Maybe this helps?

也许这可以帮助?

#1


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.

看看Knockoutjs网站上的“Cart编辑器示例”。它包括一个基于父组合框填充一个组合框的示例。

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

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

Maybe this helps?

也许这可以帮助?