尝试这个:
dojo.ready(function() {
// 1.7.2 template has 'dojoxCheckedMultiSelectHidden' className on its select from template.
// if this is different (inspect your DOM after onload), adapt the query selector
var opts = dojo.query('.dojoxCheckedMultiSelectHidden option'),
store = dijit.byId('listStore');
store.fetch({ onComplete: function(items) {
for(var i = 0; i < items.length; i++) {
if(!opts[i]) continue;
else opts[i].title = store.getValue(items[i], 'title');
}
}});
});
它的作用是,它
- 强制商店从服务器加载其数据,返回项目数组 (
query: {id:'*'}
)
- 迭代它们,将标题放在选项上。
相反,如果您通过标记部署选项,则标题属性不会与此小部件映射,只有允许作为配置参数的标记才有效。换句话说,title-attributes 被丢弃。小部件很差,并且没有与 dojotoolkit 的其余部分一起更新,所以它不是那么灵活。
当解析器在标记上运行时,它会忽略标题属性(您的标记被破坏并被 CheckedMultiSelect 模板替换,请参阅dojobase/dojox/form/resources/CheckedMultiSelect.html)。
所以,解决方案是 - 维护一个 JS 数组,映射为
// array with indexes matching the options from markup
var titles = [ "title1", "title2", "title3" ];
dojo.addOnLoad(function() {
// note, that the '_0' is a generic ID, config options are not accepting the id attribute either
// calling private function, again not correctly layed out
var childObjects = dijit.byId('dojox_form_CheckedMultiSelect_0')._getChildren();
dojo.forEach(childObjects, function(optObject, index) {
optObject.labelNode.title = titles[index];
});
});