2016-05-03 66 views
0

我是Dojo的新手。這是我遇到的問題。請求幫助。Dojo顯示/隱藏包含程序生成組合框的DIV

當選擇狀態單選按鈕時,狀態組合框應該出現。當選擇區域單選按鈕時,區域組合框應該出現。但我的代碼似乎不工作。

小提琴項目here

require([ 
 
    'dojo/dom', 
 
    'dojo/dom-construct', 
 
    'dojo/dom-style', 
 
    'dojo/query', 
 
    'dojo/on', 
 
    'dojo/store/Memory', 
 
    'dijit/form/ComboBox', 
 
    'dojo/domReady!' 
 
], function (dom, domConstruct,domStyle,query,on, Memory, ComboBox) { 
 
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"} 
 
     ] 
 
    }); 
 

 
    var regionStore = new Memory({ 
 
     data: [ 
 
      {name:"North Central", id:"NC"}, 
 
      {name:"South West", id:"SW"} 
 
     ] 
 
    }); 
 
    
 
    var comboState = new ComboBox({ 
 
     id: "stateSelect", 
 
     name: "state", 
 
     store: stateStore, 
 
     searchAttr: "name" 
 
    }, "state").startup(); 
 
    
 
    var comboRegion = new ComboBox({ 
 
     id: "regionSelect", 
 
     name: "region", 
 
     store: regionStore, 
 
     searchAttr: "name" 
 
    }, "region").startup(); 
 
    
 
    domStyle.set(dom.byId('state'), "display", "block"); 
 
    domStyle.set(dom.byId('region'), "display", "none"); 
 

 
    on(query('.radio'),'change',function(){ 
 
    query('.query').forEach(function(divElement){ 
 
     domStyle.set(divElement, "display", "none"); 
 
    }); 
 
    domStyle.set(dom.byId(this.dataset.target), "display", "block"); 
 
    }); 
 
});
.hidden { 
 
    display: none; 
 
}
<input class="radio" data-target="state" type="radio" name="selection" value="state">State 
 
<input class="radio" data-target="region" type="radio" name="selection" value="region">Region 
 

 
<div id="state" class="query hidden"></div> 
 
<div id="region" class="query hidden"></div>

+0

[如何使用Dojo顯示/隱藏的可能的複製programmaticaly通過單擊單選按鈕生成組合框?](http://stackoverflow.com/questions/36991897/how-to-use-dojo-to-show-hide-p rogrammaticaly-generated-combo-boxes-by-clicking-r) – ben

+0

你正在複製你自己的問題? – ben

回答

0

更直接的查詢,然後連接艾克:

query('.radio').on('change', function(){ 
alert("bing") 
})