以编程方式设置一个dijit选择小部件的选定值 [英] Programmatically set the selected value of a dijit Select widget
问题描述
在我的应用程序中,bus Route和Bus Route的下拉菜单巴士站下拉菜单。
用户分配了总线路线和停止点,应该是可更新的。
所以当页面首次加载时,路由下拉框中有所有路由可用,路由您当前被分配到的是所选值。停止菜单加载了与该路线相关联的所有停靠点,但没有选定的值,因此默认情况下,这是第一个选项。
每当用户更改当前选择的路线,停止菜单会相应更改,并填充与该路线相关联的所有停止。
我的问题是,使用dojo,如何设置已选择在停止菜单中的选项?
我希望它清楚当前分配给该用户的停止,而不是选择停止是第一个选项路线。
谢谢。
selectWidget.set(value,someValue);
如果您通过选项指定选项
属性(具有标签
,值
等的对象数组),然后 someValue
应该匹配其中一个对象的
值
。 (请注意,您还可以在传递给选项
的数组中的一个对象内指定选择的:true
。
如果您是通过 store
属性从dojo.data商店提供商品,那么 someValue
应该符合其中一个商店的商品的身份。
(编辑)注意:我以上假设dijit select widget你是指 dijit.form.Select
。如果您实际使用 dijit.form.ComboBox
或 dijit.form.FilteringSelect
,则同一行代码仍然保持适用于最后一段的商店。在使用选择
标签的声明式实例化的情况下,ComboBox和FilteringSelect仍会创建一个存储,其商品的标识是选择标签中选项的值。 >
I'm populating a dijit select widget with options whenever another select widget's value changes.
In my app, theres a dropdown menu for "Bus Route" and a dropdown menu for "Bus Stop". Users have assigned bus routes and stops that should be updateable.
So when the page first loads, the route dropdown box has all routes available, and the route you are currently assigned to is the selected value. The stop menu is loaded with all stops associated with that route, but there is no selected value, so, as by default, it's the first option.
Whenever the user changes the currently selected route, the stop menu changes accordingly and is populated with all stops associated with that route.
My question is, with dojo, how can I set the "Selected" option in the stop menu?
I want it to be clear which stop is currently assigned to that user, instead of the "selected" stop being the first option in the route.
Thanks.
selectWidget.set("value", someValue);
If you are specifying options via the options
property (array of objects with label
, value
, etc.), then someValue
should match the value
of one of those objects. (Note that you can also specify selected: true
right within one of the objects in the array passed to options
.)
If you are providing items from a dojo.data store via the store
property, then someValue
should match the identity of one of the store's items.
(edit) NOTE: I assumed above that by "dijit select widget" you are referring to dijit.form.Select
. If you are actually using dijit.form.ComboBox
or dijit.form.FilteringSelect
, the same line of code still holds true, as applicable to stores in the last paragraph. In the case of declarative instantiation with a select
tag, ComboBox and FilteringSelect still create a store, whose items' identities are the values of the options within the select tag.
这篇关于以编程方式设置一个dijit选择小部件的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!