本文介绍了从外部触发 Raphael 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序正在使用 Raphaël 将一组对象拖放到页面上,每个对象都绑定了一个 click 处理程序,当通过 JSON 加载对象时,该处理程序使用附加到对象的数据.一切正常.

My app is using Raphaël to drop a collection of objects onto a page, each with a click handler bound that uses data attached to the object when it was loaded in via JSON. That’s all working fine.

我现在正在尝试使用 Cucumber 添加一些测试覆盖率(是的,我知道我应该先构建测试,下次我会这样做).我需要触发对第一个对象的单击以测试该对象的关联页面是否加载.我已经尝试为该对象找到合适的 SVG 路径并针对它触发 click 事件,但这不起作用.我还尝试将每个 Raphaël 集合放入一个全局可用的对象中,但不知道如何针对适当的对象触发 Raphaël click 事件.

I now am trying to add in some test coverage using Cucumber (yes, I know I should have built the tests in first, I will do next time). I need to trigger a click on the first object to test that that object’s associated page loads. I’ve tried finding the appropriate SVG path for that object and triggering a click event against it, but that doesn’t work. I also tried dropping each Raphaël set into a globally available object but couldn’t work out how to trigger a Raphaël click event against the appropriate one.

提出一些具体问题:

1) 如何手动触发 Raphaël 事件?

1) How would one trigger a Raphaël event manually?

2) 如果您有对 Raphaël 集合拥有的 SVG 元素的引用,是否可以触发所述事件?

2) Is it possible trigger said event if you have a reference to the SVG element the Raphaël set owns?

3) 如果没有,是否可以访问 Raphaël 持有的当前集合?

3) If not, is it possible to access the current collection of sets Raphaël is holding?

推荐答案

我发现先找到 raphael 对象,然后遍历 DOM 可以让我找到他们事件处理程序的功能.对于我来说,点击事件是第 0 个事件.

I found that first finding the raphael object, then traversing the DOM allowed me to find the functions of their event handlers. For mine, the click event was the 0th event.

所以触发它我所做的就是:

So to trigger it all I did was:

 raphobj.events[0].f();

但要小心,因为如果在单击事件中引用this",它将不起作用.

Be careful though, because if in the click event you reference 'this' it won't work.

这篇关于从外部触发 Raphael 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-04 13:54