Knockout.js 根据另一个下拉菜单更改下拉菜单的可能值
我在 Knockout.JS 中遇到以下问题:
假设我有一个可观察的对象数组,在模板的帮助下呈现。它们中的每一个都有两个可观察的属性 A 和 B。这两个属性都从下拉列表中获取值(选择/选项绑定)。
我的问题是,当一个对象的 A 选定值发生更改时,我还想更改该特定对象的 B 的可用(和选定)值。我似乎无法找到如何使用淘汰赛来完成此操作。
我可以使用 Javascript 或 Jquery 将处理程序分配给下拉列表 A 的 onchange 事件并手动更改 B 的下拉选项来解决问题 - 但我真的不想用它来污染我的设计:(
所以请仅使用淘汰赛来回答我工具...
谢谢!
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 !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 Knockoutjs 网站上的“购物车编辑器示例”。它包括一个基于父组合框填充一个组合框的示例。
http://knockoutjs.com/examples/cartEditor.html
也许这有帮助?
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?