1

以下代码工作正常,但一次只有一个值,我希望选择多个值,用逗号分隔。例如,我从下拉列表中选择了阿拉巴马州,然后当我给出逗号示例:阿拉巴马州,并输入一个新字母,例如 C [示例:阿拉巴马州,C],下一组项目必须显示在下拉列表中所以最后我会在 TextBox 示例中具有以下值:Alabama,California

<html >
<head>
<link rel="stylesheet" href="dijit/themes/claro/claro.css">
    <script>dojoConfig = {parseOnLoad: true}</script>
    <script src='dojo/dojo.js'></script>
    <script>
require([
    "dojo/store/Memory", "dijit/form/FilteringSelect", "dojo/domReady!"
], function(Memory, FilteringSelect){
    var stateStore = new Memory({
        data: [
            {name:"Alabama", id:"AL"},
            {name:"Alaska", id:"AK"},
            {name:"American Samoa", id:"AS"},
            {name:"Arizona", id:"AZ"},
            {name:"Arkansas", id:"AR"},
            {name:"Armed Forces Europe", id:"AE"},
            {name:"Armed Forces Pacific", id:"AP"},
            {name:"Armed Forces the Americas", id:"AA"},
            {name:"California", id:"CA"},
            {name:"Colorado", id:"CO"},
            {name:"Connecticut", id:"CT"},
            {name:"Delaware", id:"DE"}
        ]
    });
    var filteringSelect = new FilteringSelect({
            id: "stateSelect",
            name: "state",
            value: "CA",
            store: stateStore,
            searchAttr: "name"
    }, "stateSelect");
});
</script>
</head>
<body class="claro">
    <input id="stateSelect">
<p>
    <button onclick="alert(dijit.byId('stateSelect').get('value'))">Get value</button>
    <button onclick="alert(dijit.byId('stateSelect').get('displayedValue'))">Get displayed value</button>
</p>
</body>
</html>
4

2 回答 2

0

Dojo Filtering 选择小部件不允许选择多个项目。考虑使用 Dojo MultiSelect 小部件作为替代方法。

看:

http://dojotoolkit.org/reference-guide/1.9/dijit/form/MultiSelect.html

于 2013-11-05T17:08:11.893 回答
0

你应该看看 CheckedMultiSelect:

https://dojotoolkit.org/reference-guide/1.9/dojox/form/CheckedMultiSelect.html

它同时具有下拉菜单和多选功能。要更改显示的标签,有趣的代码在函数中_updateSelection

        this.dropDownButton.set("label", this.multiple ?
            lang.replace(this._nlsResources.multiSelectLabelText, {num: i}) :
            label);

它显示标签n item(s) selected。如果您想用逗号分隔项目,这是插入代码的好地方。

于 2013-11-11T09:13:05.760 回答