我想动态创建一个div,想附加一个dojoAttachpoint。我可以这样做吗?
I want to create a div dynamically and want to attach a dojoAttachpoint. How can i do so?
以下代码用于动态添加div,但我也想附加一个dojoAttachpoint
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());推荐答案
一般来说,你不需要。 dojoAttachPoint 的目的是允许您在声明性声明的情况下,将您的dijit中的 div 特别重要的是,如果您在同一页面上创建多个dijit)。
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).
但是,因为您正在创建 div 动态地,你已经有了句柄 - 在你的情况下,变量 txt 。这将执行相同的功能。如果您需要它成为您的dijit的财产,只需创建一个:
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;更多推荐
将dojoAttachpoint与动态创建的div相关联?
发布评论