外部触发拉斐尔事件 [英] Triggering Raphael events externally

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

问题描述

我的应用程序使用Raphaël将一组对象拖放到一个页面上,每个对象都有一个点击处理程序绑定,当它通过加载时使用附加到对象的数据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路径的对象,并触发一个点击事件,但它不工作。我也尝试将每个Raphaël集合放入一个全局可用的对象,但不能解决如何触发一个Raphaël单击事件针对适当的。

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.

所以我所做的就是:

 raphobj.events[0].f();

请小心,因为如果在点击事件中引用this

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

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

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