How to get the “value” of a FilteringSelect <select> in dojo?

我只是一个虾纸丫 提交于 2019-12-06 19:56:20

问题


I am using dijit.form.FilteringSelect to provide a way to select values from a <select>. The problem is, when using dojo, the label is returned instead of the value of the s.

For example:
<select name="test" dojoType="dijit.form.FilteringSelect">
<option value="1">One</option>
<option value="2">Two</option>
</select>

Dojo is returning the literal "one" if that option is selected, instead of the value for that option, "1". The same is true for "two" and "2".

If dojo is removed from this element, the value is returned as expected.


回答1:


The dojo way to do this would be to use dijit.byId('yourDijitId').attr().

To get the value you want:

dijit.byId('yourDijitId').attr('value');

To get the value displayed in the filtering select:

dijit.byId('yourDijitId').attr('displayedValue');

EDIT: attr() was deprecated at 1.5, at 1.5 and beyond, use get()




回答2:


To get the Value of dijit.form.FilteringSelect

dijit.byId('yourId').get('value');

To get the displayedValue of dijit.form.FilteringSelect

dijit.byId('yourId').get('displayedValue');



回答3:


Ran into the same issue and came up with this solution.

var optVal = dijit.byId("yourDijitId").item.value;

The FilteringsSelect widget puts the "Display Value" in both the displayValue and value properties. The only way that I have found to get the option value is to go through the item property which lists the selected options properties.




回答4:


I have found out that dojo creates 2 elements. One using the name, which contains the value which uses the NAME of the element, and another which contains the label for the option, which uses the ID of the element. Since I was using document.getElementById(), this was returning the wrong value. Using the value from the name provides the correct result.




回答5:


For fellow Googlers out there trying to find the SELECTED OBJECT in FilteringSelect:

dijit.byId("yourDijitId").item

refers to the selected item, in case you need access to the object's other properties.

(hat tip to Bitwize for pointin to right direction with dijit.byId("yourDijitId").item.value)



来源:https://stackoverflow.com/questions/1850050/how-to-get-the-value-of-a-filteringselect-select-in-dojo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!