这是我想要实现的 - 在选择状态全名时显示状态代码。 https://dojotoolkit.org/documentation/tutorials/1.10/selects_using_stores/demos/ProgFilteringSelect.html
但为什么我无法使其发挥作用?这是dojo代码和state.json文件。
dojo.xhrGet({url: datapath,
handleAs: dataformat,
load: function (result) {
require([
'dojo/store/Memory',
'dijit/form/ComboBox',
'dojo/domReady!'
], function (Memory, ComboBox) {
stateStore = new Memory({
idProperty: "code",
data: result.states.sort(function(a,b) {
var x = a.name.toLowerCase();
var y = b.name.toLowerCase();
return x < y ? -1 : x > y ? 1 : 0;
})
});
var cboState = new ComboBox({
id: 'usastate',
name: 'usastate',
style:{width: '100%', height: '35px', fontSize: '30px'},
placeholder: 'Select a State',
store: stateStore,
searchAttr: 'name',
autocomplete: true,
onChange: function(value) {
dom.byId('statecode').innerHTML = value;
}
});
cboState.placeAt(dom.byId('state')).startup();
});
}
});
&#13;
"states": [
{
"name": "Alabama",
"abbreviation": "AL",
"code": "01"
},
{
"name": "Alaska",
"abbreviation": "AK",
"code": "02"
},
{
"name": "Arizona",
"abbreviation": "AZ",
"code": "03"
},
{
"name": "Arkansas",
"abbreviation": "AR",
"code": "04"
}
&#13;
答案 0 :(得分:1)
FilteringSelect有效。不确定为什么Combo Box不支持它。
var cboState = new FilteringSelect({
id: 'usastate',
name: 'usastate',
style:{width: '100%', height: '35px', fontSize: '30px'},
placeholder: 'Select a State',
store: stateStore,
searchAttr: 'name',
autocomplete: true,
onChange: function(value) {
dom.byId("statecode").innerHTML = value;
dom.byId("statename").innerHTML = this.get("displayedValue");
}
});
答案 1 :(得分:0)
您正在设置HTML input
元素的值,这里不应该这样做。在displayedValue
函数中设置ComboBox
的{{1}}属性。
onChange