0

我有一个 dijit.form.select,其中某些选项的是相同的(我无法更改它们以使它们不同)。我认为这可能是行为中一些怪癖的原因。例如,当我有这样的选择时:

<select id="deptSelector" data-dojo-type="dijit.form.Select">
    <option value="someuser@gmail.com">Childcare Department</option>
    <option value="someuser2@gmail.com">Health Goods Department</option>
    <option value="someuser2@gmail.com">Medicine Department</option>
    <option value="someuser3@gmail.com">Customer Service</option>
    <option value="someuser2@gmail.com">Other department</option> 
</select>

有些值是相同的,但它们的标签需要不同。但是,当我打电话时

dijit.byId(this.namespace+'deptSelector').attr('displayedValue'); 

(我读到的是获取选择标签的方法),出于某种原因,它只是让我在选择中获得具有相同值的第一个选项。例如,如果我选择“其他部门”,它将给我“保健品部门”。我不明白为什么会发生这种情况,因为我认为它只是应该获得 DISPLAYED 值,而不是基于所选项目的值的结果。

这是预期的行为吗?如果是这样,在不更改值的情况下,我可以做些什么来获得正确的标签?

先感谢您!

4

3 回答 3

0

var label = registry.byId("deptSelector").get("displayedValue");

注册表来自 dijit/registry。

于 2013-08-07T15:21:16.073 回答
0

我建议改用商店将数据与 html 分开。您可以执行以下操作:

网页:

<select id="deptSelector"></select>
<div id="output"></div>

Javascript:

require(['dijit/form/Select',
    'dijit/registry',
    'dojo/html',
    'dojo/store/Memory',
    'dojo/domReady!'], function (Select, registry, html, Memory) {

    var departments = new Memory({
        data: [{
            id : 1,
            name: "Childcare Department",
            email: "someuser@gmail.com"
        }, {
            id : 2,
            name: "Health Goods Department",
            email: "someuser2@gmail.com"
        }, {
            id : 3,
            name: "Medicine Department",
            email: "someuser2@gmail.com"
        }, {
            id : 4,
            name: "Customer Service",
            email: "someuser3@gmail.com"
        }, {
            id : 5,
            name: "Other Department",
            email: "someuser2@gmail.com"
        }]
    }),
    deptSelector = new Select({
        store: departments,
        labelAttr : 'name'
    }, 'deptSelector');

    deptSelector.on('change', function (value) {
        html.set('output', departments.get(deptSelector.get('value')).email);
    });

    deptSelector.startup();

    html.set('output', departments.get(deptSelector.get('value')).email);

});

http://jsfiddle.net/psoares/kzWdV/

于 2013-08-05T14:51:56.140 回答
0

尝试

dijit.byId(this.namespace+'deptSelector').focusedChild.label
于 2013-08-02T20:57:12.773 回答