2013-08-22 187 views
0

我在測試文件中有以下內容。我正在嘗試將選定的值從filteringselect寫入divid。它第一次正常工作,但下一次沒有發生過濾(下拉菜單中沒有可用的值)。 對於第一次更改過濾選擇onchange被調用成功。FilteringSelect第二次不工作

請幫助我找到問題。我是道場新手。 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> 

回答

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 + [...] 
}