将dojoAttachpoint与动态创建的div相关联? [英] Associating a dojoAttachpoint to a div created dynamically?

查看:348
本文介绍了将dojoAttachpoint与动态创建的div相关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动态创建一个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相关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆