dojo 拖放:如何为放置事件添加处理程序

发布于 2024-09-28 07:40:04 字数 391 浏览 0 评论 0原文

我有一个像这样的简单列表:

<div dojoType="dojo.dnd.Source" id="myList">
    <div class="dojoDndItem">item 1</div>
    <div class="dojoDndItem">item 2</div>
    <div class="dojoDndItem">item 3</div>
</div>

我使用 dojo 属性使列表可排序。

它的工作没有任何问题,但如何在项目被删除时向事件添加侦听器?如果用户释放鼠标并且元素捕捉到位,我需要一个 javascript 函数来处理此事件。如何通过标记添加它?

I have a simple list like this:

<div dojoType="dojo.dnd.Source" id="myList">
    <div class="dojoDndItem">item 1</div>
    <div class="dojoDndItem">item 2</div>
    <div class="dojoDndItem">item 3</div>
</div>

And I use the dojo attributes to make the list sortable.

It works without any problems, but how do I add a listener to the event when an item is dropped? If the user releases the mouse and the element snaps in place I want a javascript function to handle this event. How can I add it via markup?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜扑 2024-10-05 07:40:04

您可能感兴趣的扩展点是 Source 上的 onDrop 方法。您可以使用解析器理解的

<div dojoType="dojo.dnd.Source" id="myList">
    <script type="dojo/connect" event="onDrop" args="source, nodes, copy">
        console.log('received drop event:', source, nodes, copy);
    </script>
    <div class="dojoDndItem">item 1</div>
    <div class="dojoDndItem">item 2</div>
    <div class="dojoDndItem">item 3</div>
</div>

请注意,我连接到方法,因为 dojo.dnd.SourceonDrop 方法及其在默认实现中调用的方法中有重要的功能;如果我使用

以下 SitePen 博客文章提供了有关解析器中可用的此功能的更多信息: http://www.sitepen.com/blog/2007/09/21/dojo-09-power-tools-script-typedojomethod/

The extension point you're probably interested in is the onDrop method on the Source. You can use the <script type="dojo/..."> syntax understood by the parser to accomplish this declaratively, e.g.:

<div dojoType="dojo.dnd.Source" id="myList">
    <script type="dojo/connect" event="onDrop" args="source, nodes, copy">
        console.log('received drop event:', source, nodes, copy);
    </script>
    <div class="dojoDndItem">item 1</div>
    <div class="dojoDndItem">item 2</div>
    <div class="dojoDndItem">item 3</div>
</div>

Note that I connect to the method because there is important functionality within dojo.dnd.Source's onDrop method, and the methods it invokes in its default implementation; if I were to override the function instead by using <script type="dojo/method">, that default functionality would be clobbered.

The following SitePen Blog post gives more information on this feature available in the parser: http://www.sitepen.com/blog/2007/09/21/dojo-09-power-tools-script-typedojomethod/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文