简体   繁体   English

如何获得对dojo.xhrPost加载内的点火dom节点的访问?

[英]How can you get access to the firing dom node inside a dojo.xhrPost load?

I have an html fragment like the following: 我有一个类似下面的html片段:

<li>
    <img src="/jsafe/gallery/item/83/thumb" />
    <span class="tools">
        <a href="/jsafe/gallery/item/83/rotate/left">
            <img src="/jsafe/img/rotate_left_small.png" alt="Rotate Left"/>
        </a>

        <a href="/jsafe/gallery/item/83/rotate/right">
            <img src="/jsafe/img/rotate_right_small.png" alt="Rotate Right"/>
        </a>
    </span>
</li>

I have a dojo fragment like the following: 我有一个dojo片段,如下所示:

dojo.query(".tools a:nth-child(1)").forEach(function(node,index,arr){
    dojo.connect(node, "onclick", null, function(e){
        e.preventDefault();
        dojo.xhrPost({
            url: dojo.attr(e.currentTarget, "href"),
            handleAs: "json",
            load: function(data) {
                //TODO
            }
            },
            error: function(error) {
                var u = "";
            }
        });
    })
});

Inside the load function how can I get to the e.currentTarget dom node? 在load函数内部,如何到达e.currentTarget dom节点? I know load is a separate callback function but I need to get to that dom node to do more manipulation. 我知道加载是一个单独的回调函数,但是我需要进入dom节点才能进行更多操作。

Did you try just referring to e.currentTarget from within the load function? 您是否尝试仅从load函数中引用e.currentTarget :) :)

Since your load function is defined within the event handler function which has access to e , you still have access to it. 由于您的load功能是在可以访问e的事件处理函数中定义的,因此您仍然可以访问它。

Perhaps the explanation here will help: https://developer.mozilla.org/en/JavaScript/Guide/Closures 也许这里的解释会有所帮助: https : //developer.mozilla.org/en/JavaScript/Guide/Closures

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM