Associating a dojoAttachpoint to a div created dynamically?

北慕城南 提交于 2019-12-12 19:15:49

问题


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



来源:https://stackoverflow.com/questions/5509365/associating-a-dojoattachpoint-to-a-div-created-dynamically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!