$.Controller("Whiteboard", {}, {
init: function(){
var pen = new Pen();
},
sendRequest: function() {
// This function should listen draw/erasing events from Pen
}
});
$.Class("Pen",{},{
init: function() {
// Pen setup, click to draw etc..
}
});
这样的事情,我希望白板听Pen的事件,我该怎么做?我需要Controller听一堂课。
答案 0 :(得分:0)
如果这是JMVC 3.2+,你可以something like this:
$('.whiteboard').whiteboard({pen:new Pen()});
$.Controller("Whiteboard", {}, {
"{pen} draw": function() {
this.sendRequest();
}
});
$.Observe('Pen',{},{
draw: function() {
$(this).triggerHandler('draw');
}
});
对于JMVC 3.1,您必须使用$.Model
代替$.Observe
并在控制器中使用this.bind
,如下所示:
$.Controller("Whiteboard", {}, {
init: function() {
this.bind(this.options.pen,'draw',this.callback('sendRequest'));
}
});