视图和控制器彼此不可见?怎么会这样呢?
我读过,视图和控制器应该彼此不可见。
然后控制器如何侦听 UI 视图中的按钮单击?
当然,控制器需要了解要添加事件监听器的视图或者 UI 视图需要调用控制器中的函数,或者向控制器分派事件。
I have read that Views and Controllers should be invisible to each other.
How does the controller then listen for say a button click in the UI view?
Surely the controller needs to know about the view to addEventListeners or the UI view needs to call functions in the controller, or dispatch events to the controller.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对 MVC 的唯一经验是使用 Robotlegs 框架,因此我将尝试解释使用此框架时的方法。
我的视图仅使用本机 Flash 事件(MouseEvent.CLICK 等),这些事件在视图的中介器中侦听。当中介器接收到本机事件时,它将调度一个特定于应用程序的事件(例如 LoginEvent.LOGIN),可以使用上下文中的命令映射将其映射到然后触发命令。
抱歉,如果这没有多大意义,但基本上您的视图会触发本机事件,并且您的调解器将侦听这些本机事件,然后触发应用程序特定事件,这些事件又会运行您的命令。您将调解者用作您观点的“耳朵”,并排除他们的任何逻辑。应用程序上下文允许您在发生某些事件时触发命令,以便将视图和命令分开。
My only experience of MVC is with using the robotlegs framework so I'll try explain my approach when using this framework
My views only use native flash events (MouseEvent.CLICK etc) which are listened for in the mediator for the view. When the mediator receives a native event it will then dispatch an application specific event, LoginEvent.LOGIN for example, which can be mapped to then fire a command using the command map on your context.
Sorry if that doesn't make much sense, but basically your views fire native events and your mediators will listen for these native events and then fire application specific events which in turn run your commands. You use the mediator as the 'ears' for your view and keep any logic out of them. The application context allows you to fire commands whenever certain events occur so your views and commands are seperated.