2012-07-16 113 views
1

我有dojox.form.CheckedMultiSelectDojo。從JSON設置屬性作爲HTML屬性

<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} 

我怎樣才能從JSON設置爲 「items.title」 屬性作爲HTML屬性 「稱號」到每個複選框將爲CheckedMultiSelect創建?

回答

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. 迭代,將標題放置在選項上。

如果您要通過標記部署選項,標題屬性不會與此小部件映射,只有作爲配置參數允許的標記有效。換句話說,標題屬性被丟棄。該小部件相當差,並沒有更新dojotoolkit的其餘部分,所以它不是那麼靈活。

當分析器運行在的標記,它忽略了title屬性(您的標記被摧毀,由CheckedMultiSelect模板更換,見dojobase/DojoX中/表格/資源/ 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]; 
    }); 

}); 
+0

怎麼就這樣猶豫不決?有問題,或者你有EM排序? – mschr 2012-07-27 16:52:59