设置dijit.form.Select小部件的值(选定选项) [英] Setting the value (selected option) of a dijit.form.Select widget

查看:123
本文介绍了设置dijit.form.Select小部件的值(选定选项)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个dijit.form.Select小部件。如果重要的话,它与数据存储相关。它已经充满了几个选项。所有我想做的是以编程方式设置其值。我可以使用 myWidget.attr('value')获取其值,但如果我尝试执行 myWidget.attr('value',5)例如(其中5是有效值之一),所有这一切都是重置该小部件以选择第一个选项,无论我给予什么价值。



这似乎是一个错误,没有任何测试或文档显示如何完成我想要的。但是有没有办法,即使这是一个肮脏的黑客?



我使用的是Dojo 1.4.0。请注意,dijit.form.Select是dojox.form.DropDownSelect的新名称。



编辑:我甚至尝试使用所有新选项重置该小部件,但它忽略选项,其中 selected = true ,只需选择第一个选项。

解决方案

即使你的值是int,如果你将整数设置为一个字符串,那么这个将会工作。

  dijit.byId('my_select').attr('value',String(5)); 


I have a dijit.form.Select widget. It's tied to a data store, if that matters. It's filled with several options already. All I want to do is programmatically set its value. I can get its value using myWidget.attr('value') but if I try to do myWidget.attr('value', 5) for example (where 5 is one of the valid values), all it does is reset the widget to select the very first option, no matter what value I give it.

This seems to be a bug, and there aren't any tests or documentation which show how to accomplish what I want to. But is there some way, even if it's a dirty hack?

I'm using Dojo 1.4.0. Note that dijit.form.Select is the new name for dojox.form.DropDownSelect.

edit: I even tried resetting the widget with all new options, but it ignores the option which has selected = true and just selects the first option. There must still be a way though.

解决方案

Even if your values are ints, if you set your integer to a string then this will work.

dijit.byId( 'my_select' ).attr( 'value', String( 5 ) );

这篇关于设置dijit.form.Select小部件的值(选定选项)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆