简体   繁体   English

无法在dojo Select中选择任何选项

[英]Not able to select any options in dojo Select

I am using dojo 1.6 and the problem I have encountered is quite unique. 我正在使用dojo 1.6,遇到的问题非常独特。 Check out the following code: 查看以下代码:

var dd = new dijit.form.Select({
        id: 'dd', 
        options: [{label:'option1'}, {label: 'option2'}],
    }); 
dojo.connect(dd, "onChange", this, function (){
        console.debug("trying to catch the change");
    });

So as per the above code I should be getting a drop down and be able to change the value in the drop and catch the event in dojo.connect . 因此,按照上面的代码,我应该下拉菜单,并能够更改下拉菜单中的值并捕获dojo.connect的事件。 While I do get a drop down which by default has option1 selected, however I am not able to select option2 . 虽然我确实获得了一个下拉列表,默认情况下已选择了option1 ,但是我无法选择option2 Please note that both the options are visible in the drop down but the selection doesn't work. 请注意,这两个选项在下拉菜单中均可见,但选择不起作用。 I am fairly new at dojo but from all the examples this seems to be the minimum requirement to make a drop down. 我在dojo相当陌生,但是从所有示例来看,这似乎都是进行下拉的最低要求。 I would appreciate any feedback. 我将不胜感激任何反馈。 EDIT: So turns out if I set options like [{label: 'option1', value: 1}, {label: 'option2', value:2}] then everything works as I want to. 编辑:原来,如果我设置了[{label: 'option1', value: 1}, {label: 'option2', value:2}]这样[{label: 'option1', value: 1}, {label: 'option2', value:2}]那么一切都会按我的意愿进行。 But can some one please explain what is the role of value here and why does it have to be in integer all the time? 但是,有人可以在这里解释值的作用吗,为什么它必须一直都是整数?

The value is the text that will be sent to the server if you submit a form containing your select. 该值是如果您提交包含所选内容的表单将发送到服务器的文本。

It's similar to an option tag with a value attribute: <option value="op1">option1</option> . 它类似于具有值属性的option标签: <option value="op1">option1</option> If you omit the value attribute on tag, the submitted text will simply be the label text "option1". 如果您省略了标签上的value属性,则提交的文本将只是标签文本“ option1”。

The values don't have to be integers - you can have options with {label: foo, value: foo} , as long as foo is unique among the options. 值不必是整数-您可以使用{label: foo, value: foo}的选项,只要foo在选项中是唯一的即可。 If you omit the value property here, the submitted value will be undefined, and the dijit will (as you've noticed) behave generally strange. 如果您在此处省略value属性,则提交的值将是不确定的,并且dijit(如您所注意到的)的行为通常很奇怪。

Edit after a bit of experimentation: When using the Select dijit, the values in the options array (or, in fact, the ids in a store) must be strings. 经过一番试验后进行编辑:使用Select dijit时, options数组中的值(或实际上是商店中的id)必须为字符串。 Otherwise, giving the select a default value will not work. 否则,为选择提供默认值将不起作用。 Eg: 例如:

new Select({
    value: 3,
    options: [ {label: "foo", value: 1}, {label: "bar", value: 3}]
})

.. will not set "bar" as the default selected option, and highlighting the selected item in the dropdown doesn't work. .. 不会将“栏”设置为默认的选定选项,并且在下拉菜单中突出显示所选项目无效。 You have to use an option array with string values: 您必须使用带有字符串值的选项数组:

    options: [ {label: "foo", value: "1"}, {label: "bar", value: "3"}]

Not 100% sure about the reason behind this. 并非100%知道其背后的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM