我在DAG中有一个joint.js元素,并希望能够通过单击它来触发事件。
我可以使用$(selector).click(...)
实现这一点,但我想知道是否有特定于joint.js的处理方式,因为那可能更好。我决定将'batch:stop'事件作为onclick的候选事件之一。
我的代码:
var variable = new joint.shapes.basic.Rect({
name : label,
id: label,
onclick : function () {alert("hello");},
size: { width: width, height: height },
attrs: {
text: { text: label, 'font-size': letterSize, 'font-family': 'monospace' },
rect: {
fill : fillColor,
width: width, height: height,
rx: 5, ry: 5,
stroke: '#555'
}
}
});
variable.on('batch:stop', function (element) {alert(""); toggleEvidence(element.name);});
return variable;
我应该如何添加 onclick 事件?