labelType 不适用于 dijit/forms/select

labelType not working on dijit/forms/select

给dijit/forms/select添加一个选项,就是这样,

"<nav asdasd>"

由于 dijit/forms/select,默认情况下使用 labelType = "html",我将 labelType 设置为 'text' 但即便如此,该选项仍作为 HTML 元素添加。

HTML

<select id="select1" data-dojo-type="dijit/form/Select" data-dojo-props="labelType:'text'" style="width:150px;"></select>

Javascript(道场)

require([
"dojo/ready",
"dojo/_base/lang",
"dijit/registry"], function (ready,lang,registry) {

ready(function () {

    var select1 = registry.byId("select1");

    option1 = {
        value: "o1",
        label: "option 1",
        selected: false
    };

    option2 = {
        value: "o2",
        label: "option 2",
        selected: true
    };

    option0 = {
        value: "o",
        label: "<nav asdasd>",
        selected: false
    };

    select1.addOption(lang.clone(option1));
    select1.addOption(lang.clone(option2));
    select1.addOption(lang.clone(option0));

});

});

http://jsfiddle.net/gsbc25as/1/

这应该有效:

require([
    "dojo/ready",
    "dojo/_base/lang",
    "dijit/registry"], function (
ready,
lang,
registry) {

    ready(function () {

        var select1 = registry.byId("select1");

      var  option1 = [
            {
            value: "o1",
            label: "option 1",
            selected: false
        },
            {
            value: "o2",
            label: "option 2",
            selected: false
        },
            {
            value: "o",
            label: "&ltnav Assad&gt",
        selected: true
    } ]

        select1.addOption(lang.clone(option1));

    });
});

我注意到您的 JSFiddle 运行正在针对 Dojo 1.9。如果您针对 Dojo 1.10 切换到 运行,它会像您期望的那样工作。

labelType 属性 仅在 Dojo 1.10 中添加。

对于那些希望通过修复使用 Dojo 1.9 的人,

http://jsfiddle.net/gsbc25as/6/

require([
"dojo/ready",
"dojo/_base/lang",
"dijit/registry",
"dojox/html/entities"], function (ready,lang,registry,entities) {

ready(function () {

    var select1 = registry.byId("select1");

    option1 = {
        value: "o1",
        label: "option 1",
        selected: false
    };

    option2 = {
        value: "o2",
        label: "option 2",
        selected: true
    };

    option0 = {
        value: "o",
        label: entities.encode("<nav asdasd>"),
        selected: false
    };

    select1.addOption(lang.clone(option1));
    select1.addOption(lang.clone(option2));
    select1.addOption(lang.clone(option0));

});

});