Dijit 组合框的问题设置值
Dijit Trouble set value of the combobox
我在设置 dojo combobox
的值时遇到问题,组合框是:
<select data-dojo-type="dijit.form.ComboBox" id="index" name="index" onChange="comboOnChange()">
<option value="30" >30</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
我已经尝试了所有这些选项:
dojo.widget.byId('index').setValue(index);
index.options[index.selectedIndex].text = index;
dijit.byId('index').set("value", index);
None 成功了,有什么建议吗?
我不知道您是否使用旧版 dojo 模式。但从 1.6 开始,dojo 使用 AMD 风格。在你的情况下,dijit.byId('index').set("value", index);
应该可以工作,如果有错误,请查看你的控制台!
但我强烈建议使用现代 Dojo (AMD),上面你会找到一个工作示例(它以 30 开头然后更改为 50):
require(["dojo/ready", "dojo/parser","dijit/registry","dijit/form/ComboBox","dojo/domReady!"],
function (ready, parser, Registry ,Combobox) {
parser.parse();
//be sure the widget is rendered and parsed , by calling ready
ready(function(){
//get reference to combo widget
var combo = Registry.byId("index");
// atach change event
combo.on("change",function(e){
console.log(e);
alert(this.value);
});
//here you can set value to your combo set value
combo.set("value",50);
});
});
html, body {
height: 100%;
padding: 0;
margin: 0;
font-family: Lucida Sans,Lucida Grande,Arial !important;
font-size: 13px !important;
background: white;
color: #333;
}
<link href="https://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dijit/themes/claro/claro.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<script>
dojoConfig= {
parseOnLoad: false,
async: true
};
</script>
<body class="claro">
<select data-dojo-type="dijit/form/ComboBox" id="index" name="index">
<option value="30" >30</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</body>
我在设置 dojo combobox
的值时遇到问题,组合框是:
<select data-dojo-type="dijit.form.ComboBox" id="index" name="index" onChange="comboOnChange()">
<option value="30" >30</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
我已经尝试了所有这些选项:
dojo.widget.byId('index').setValue(index);
index.options[index.selectedIndex].text = index;
dijit.byId('index').set("value", index);
None 成功了,有什么建议吗?
我不知道您是否使用旧版 dojo 模式。但从 1.6 开始,dojo 使用 AMD 风格。在你的情况下,dijit.byId('index').set("value", index);
应该可以工作,如果有错误,请查看你的控制台!
但我强烈建议使用现代 Dojo (AMD),上面你会找到一个工作示例(它以 30 开头然后更改为 50):
require(["dojo/ready", "dojo/parser","dijit/registry","dijit/form/ComboBox","dojo/domReady!"],
function (ready, parser, Registry ,Combobox) {
parser.parse();
//be sure the widget is rendered and parsed , by calling ready
ready(function(){
//get reference to combo widget
var combo = Registry.byId("index");
// atach change event
combo.on("change",function(e){
console.log(e);
alert(this.value);
});
//here you can set value to your combo set value
combo.set("value",50);
});
});
html, body {
height: 100%;
padding: 0;
margin: 0;
font-family: Lucida Sans,Lucida Grande,Arial !important;
font-size: 13px !important;
background: white;
color: #333;
}
<link href="https://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dijit/themes/claro/claro.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<script>
dojoConfig= {
parseOnLoad: false,
async: true
};
</script>
<body class="claro">
<select data-dojo-type="dijit/form/ComboBox" id="index" name="index">
<option value="30" >30</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</body>