How to dynamically create a dojo button using option such as iconClass -


i want dynamically create dojo button, , have issue use option such as iconclass.

here how create button

<td valign="middle" align="   <button data-dojo-type="dijit/form/button" data-dojo-props="iconclass:'icon_btn_add', showlabel: false" type="button" onclick='require(["routeview.js"], function( s ) { s.cb_click_btn_add(1); })' id="id_btn_add_0"  </td> 

i have tried

btn = new button({    "data-dojo-props": "iconclass:icon_btn_add, showlabel: false",    "onclick": "require(['routeview.js'], function( s ) {       s.cb_click_btn_add("+(n)+       "id": "id_btn_add_"+n,       "disabled": "true"    }, id_td3); 

and this:

domconstruct.create("button", {        "data-dojo-type": "dijit/form/button",       "data-dojo-props": "iconclass:icon_btn_add, showlabel: false",       "type": "button",       "onclick": "require(['routeview.js'], function( s ) { s.cb_click_btn_add("+(n+1)+"); })",       "id": "xid_btn_add_"+n,       "disabled": "true"     }, id_td3, "last"); 

the "data-dojo-props" property not taken in account.

how can create dynamically dojo button , use iconclass ?

i'm assuming you're creating dojo widgets via html delcaration method. therefore, declaring button via data-dojo-type attribute in html like:

<button id="an_id_for_your_button" data-dojo-type="dijit/form/button" data-dojo-props="iconclass:'icon_btn_add', showlabel: false"></button> 

dojo create button , record reference created button widget in registry same id original button. can reference so:

   require([ ..., "dijit/registry", ...], function(..., registry, ...) {       var btn = registry.byid("id_btn_add_0");       btn.set("onclick", function(e) {...});        // although once in javascript realm consider using "on"       btn.on("click", function(e) {...});    });  

note object returned "registry.byid()" different object dom node returned "dom.byid". more info buttons can found: http://dojotoolkit.org/reference-guide/1.10/dijit/form/button.html

for consideration can practice avoid declaring event handlers in html tags (particularly dojo). html declared event handlers force handlers in global scope , controlling "this" scope can tricky.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -