如何创建外部按钮来操作单元格



我想在外面有外部按钮,可以在图形上执行一些操作。

App.MainView = joint.mvc.View.extend({
events: {
'click #multiplyBtn': 'testCell'
},
testCell: function() {
console.log('hi');
console.log(this.selection);
},

我尝试将其包含在main中.js就像这样,但它不起作用。

我也尝试设置 jquery 事件处理程序,但我不确定将代码放在哪里,因为我总是得到未定义的选择值

events哈希引用在视图中工作。在您的代码中,它假定#multiplyBtn是视图模板的一部分。如果要将视图方法附加到"外部"元素操作,则必须使用 jQuery 在视图的 init 方法中执行绑定:

initialize: function () {
$('#multiplyBtn').on('click', this.testCell.bind(this));
}

最新更新