道场。将属性从JSon设置为HTML属性 [英] Dojo. Set attribute from JSon as HTML attribute

查看:127
本文介绍了道场。将属性从JSon设置为HTML属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 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看起来像:

The JSon for store looks like:

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

如何将JSon中的 items.title/c $ c>属性设置为HTML属性每个复选框的标题将为 CheckedMultiSelect 创建的复选框。

How I can set "items.title" attribute from JSon as HTML attribute "title" to each checkbox which will created for CheckedMultiSelect?

推荐答案

尝试这样:

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. 强制商店从服务器加载数据,返回items数组( query:{id:'*'}

  2. 重复它们,将标题放在选项上。

如果您通过标记部署您的选项,则标题属性不会与此小部件映射,只有标记可被允许作为配置参数有效。换句话说,标题属性被放弃。该小部件很差,并没有更新与其余的dojotoolkit,所以它不是那么灵活。

If instead youre deploying your options via markup, the title attributes are not mapped with this widget, only markup which is allowed as configure parameters are valid. In other words, title-attributes are discarded. The widget is quite poor and has not updated with the rest of dojotoolkit, so it is not that flexible.

当解析器运行在标记上时,它忽略标题属性(您的标记被销毁并被CheckedMultiSelect模板替换,请参见 dojobase / dojox / form / resources / CheckedMultiSelect.html )。

When parser runs over the markup, it ignores the title attribute (your markup gets destroyed and replaced by the CheckedMultiSelect template, see dojobase/dojox/form/resources/CheckedMultiSelect.html).

所以,解决方案是 - 维护一个JS数组,与

So, solution is - maintain a JS array, mapped with

// 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];
  });

});

这篇关于道场。将属性从JSon设置为HTML属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆