0
$.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 的白板监听事件,我该怎么做?我需要控制器监听一个类。

4

1 回答 1

0

如果这是 JMVC 3.2+,您可以执行以下操作:

$('.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'));
    }
});
于 2012-05-16T18:42:15.113 回答