我将'mousedown'事件侦听器添加到CompoundPath(而不是其子对象)。但是我需要知道事件发生在哪个孩子身上。事件对象的'target'属性将返回CompoundPath。那么,解决方案是什么?
const circle1 = new Path.Circle({
center: view.center - 50,
radius: 50
});
const circle2 = new Path.Circle({
center: view.center + 50,
radius: 50
});
const compoundPath = new CompoundPath({
children: [circle1, circle2],
fillColor: 'orange',
onMouseDown: event => {
if (circle1.hitTest(event.point)) {
alert('circle 1 clicked');
} else if (circle2.hitTest(event.point)) {
alert('circle 2 clicked');
}
}
});