0

我在测试文件中有以下内容。我正在尝试将过滤选择中的选定值写入除法。第一次它工作正常,但下一次过滤没有发生(下拉列表中没有可用的值)。对于第一次更改过滤选择,成功调用 onchange。

请帮助我找到问题。我是道场新手。DOJO 版本 - DOJO 1.8

<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",
            placeHolder: "Select a State",
            store: stateStore,
            searchAttr: "name",
            onChange: function(value) {
                var text1 = document.getElementById("divid").innerHTML
                document.getElementById("divid").innerHTML = text1 + dijit.byId('stateSelect').attr('displayedValue') + ';';
            }
        }, "stateSelect");
    });
</script>

<div id="divid">
    Select a State : <input id="stateSelect">
</div>
4

1 回答 1

1

您的错误是由于您记录输出的方式:

var text1 = document.getElementById("divid").innerHTML;
document.getElementById("divid").innerHTML = text1 + [...]

由于 'divid' 包含 FilteringSelect dijit 标记,再次设置 divid.innerHTML 会覆盖现有的 DOM 并弄乱现有的 FilteringSelect dijit 实例。通常,您不应修改 dijit 实例的 DOM。只需在标记中添加一个空的 span 元素即可记录您的值:

<div id="divid">
Select a State : <input id="stateSelect">
<span id="buffer"></span>
</div>

和 onChange 变成:

onChange: function(value){
var text1 = document.getElementById("buffer").innerHTML;
document.getElementById("buffer").innerHTML = text1 + [...]
}
于 2013-08-22T12:29:54.680 回答