1

我有dojox.form.CheckedMultiSelect

<span dojoType="dojo.data.ItemFileReadStore" url="..." jsId="listStore"></span>
<select id="unsubscribedList" class="soria" dojoType="dojox.form.CheckedMultiSelect" 
multiple="true" onchange="..." store="listStore" title="title"></select>

商店的 JSON 看起来像:

{"items":[{"title":"ESC, MICHAEL (MESC)","value":"1000","label":"ESC, MICHAEL"},...}]
,"totalCount":7,"endList":7,"label":"label","identifier":"value","startList":1}

如何将“ items.title”属性从 JSon 设置为 HTML 属性“标题”到每个将要创建的复选框CheckedMultiSelect

4

1 回答 1

1

尝试这个:

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');
       }

    }});
});

它的作用是,它

  1. 强制商店从服务器加载其数据,返回项目数组 ( query: {id:'*'})
  2. 迭代它们,将标题放在选项上。

相反,如果您通过标记部署选项,则标题属性不会与此小部件映射,只有允许作为配置参数的标记才有效。换句话说,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];
  });

});
于 2012-07-16T11:18:10.633 回答