Associating a dojoAttachpoint to a div created dyn

2019-07-07 19:41发布

问题:

I want to create a div dynamically and want to attach a dojoAttachpoint. How can i do so?

Following code is used to add a div dynamically, but i want to attach a dojoAttachpoint too

var txt = dojo.create("div", {
    id: "alert",
    role: "alert",
    'class': "contenthide",
    innerHTML: msg
}, dojo.body());

回答1:

Generally, you shouldn't need to. The dojoAttachPoint's purpose to allow you to get an unambigious handle onto the div within your dijit when it's declared declaratively (particularly important if you are creating more than one of your dijit on the same page).

However, because you are creating the div dynamically, you already have the handle - in your case, the variable txt. This will perform the same function. If you need it to become a property of your dijit, just create one:

this._myDivsPseudoAttachPoint = txt;


回答2:

As i know, you can use dojoAttachPoint only in widget template string dojo-what-is-a-widget

dojoAttachPoint, dojoAttachEvent, waiRole, waiState attributes documentation