开发者

MVC Pattern - Bind event listeners from controller onto views elements?

How do you bind an event listener from the contr开发者_开发知识库oller to the view's elements eg button (click event) to its own handler?

Originally I was doing this from the view eg.

button.addEventListener(MouseEvent.CLICK, controller.buttonClick);

But now realise this is wrong since reading "each view is only supposed to "know" about the model which it represents, and "know" nothing of the controller"


model should have instance of this button, so controller will access model to add event listener, but view will only show this button, only add to stage.


Controller has direct reference to the view so can bind event listeners to the appropriate view elements. View can expose public methods to set bindings if you like.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜