嘿,我使用下面的代碼來製作級聯下拉列表,其中,我做了一個函數xyz(),其中ajax被稱爲誰調用servlet並設置結果變量中的值,值在結果是用逗號分隔,所以我用逗號分隔它和商店到第二下拉..現在的問題是,當我改變第一下拉第二下拉不填充,但阿賈克斯被稱爲,當我改變值第二時間,然後第二dropdwn被填充錯誤的值,它是我選擇預覽..請告訴我,什麼是錯使用dojo ajax填充下拉列表
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" href="js/dojo/dijit/themes/claro/document.css"/>
<link rel="stylesheet" href="js/dojo/dijit/themes/claro/claro.css" />
<script src='js/dojo/dojo/dojo.js' data-dojo-config=' parseOnLoad: true'></script>
<script>
dojo.require("dijit.form.ComboBox");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojo.ready");
dojo.require("dojo.store.Memory");
require(["dojo/parser", "dijit/form/ComboBox","dijit/form/TextBox","dojo/dom-construct"]);
function xyz(){
dojo.xhrPost({
// The URL to request
url: "populate",
timeout : 3000 ,
content: {
username: document.getElementById("state").value
},
load: function(result) {
require(["dijit/form/ComboBox", "dojo/ready","dojo/store/Memory"],
function(ComboBox,ready,Memory){
ready(function() {
dojo.connect(dijit.byId('state'), 'onChange', function() {
var stateSelect = dijit.byId('stateSelect');
if (!stateSelect) {
stateSelect = new ComboBox({id: "stateSelect",name:"select",value: "Select",searchAttr:"name"},"stateSelect");
}
var str_array = result.split(',');
var data = [];
dojo.forEach(str_array, function(item, idx) {
data.push({
id: idx,
name: item
});
stateSelect.set('store', new Memory({data: data}));
});
}); // dojo.connect
}); // ready
}); // require
}
});
}
</script>
</head>
<body class="claro">
<select data-dojo-type="dijit.form.ComboBox" id="state" name="state" onchange="xyz()" >
<option selected>Andaman Nicobar</option>
<option>Andhra Pradesh</option>
<option>Arunachal Pradesh</option>
</select>
<select data-dojo-type="dijit.form.ComboBox" id="stateSelect" name="stateSelect">
</select>
</body>