javascript Knockout.js 根据另一个下拉列表更改下拉列表可能的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7977487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Knockout.js change dropdown possible values based on another dropdown
提问by Serafeim
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.
我的问题是,当一个对象的 A 的选定值发生变化时,我还想更改该特定对象的 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 来解决这个问题,将处理程序分配给下拉 A 的 onchange 事件并手动更改 B 的下拉选项 - 但是我真的不想用它来污染我的设计:(
So please answer me using only knockout's tools...
所以请只使用淘汰赛的工具回答我......
Thanks !
谢谢 !
回答by Mark Robinson
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 网站上查看“购物车编辑器示例”。它包括一个基于父组合框填充一个组合框的示例。
http://knockoutjs.com/examples/cartEditor.html
http://knockoutjs.com/examples/cartEditor.html
Maybe this helps?
也许这有帮助?