简体   繁体   English

MVC-视图的角色

[英]MVC - View's Role

I'm having a difficult time in implementing MVC's View and View's responsibilities. 我在执行MVC的View和View的职责时遇到了困难。 By the way I'm implementing the MVC in new way, not smalltalk's traditional way (controller between model and view. View does not have a relation with model vice versa) 顺便说一下,我以新的方式实现了MVC,而不是Smalltalk的传统方式(模型和视图之间的控制器。视图与模型没有关系,反之亦然)

My problem is sth like following. 我的问题是…… My View have a test list shown as a table, each table row corrensponds to a single test and user can select more than one test. My View的测试列表显示为表格,每个表格行对应一个测试,用户可以选择多个测试。 And each test (row) may have 0 or more options for the selected test. 并且每个测试(行)对于所选测试可能具有0个或更多选项。 After clicking 'start test' button, my application is supposed to execute selected tests with their selected options. 单击“开始测试”按钮后,我的应用程序应使用其选定的选项执行选定的测试。

How should I implement this part of my application so that controller is informed about the selected tests and parameters? 我应该如何实现我的应用程序的这一部分,以便控制器了解所选的测试和参数? Should the view provide the information about selected tests and parameters?(makes View a little intelligent, not dumb as desirerd ?) 该视图是否应该提供有关所选测试和参数的信息?(使View变得有些智能,而不是愚蠢的愿望?)

Should the view provide information by going through all rows of table and checking the parameters(hence no dedicated 'selected tests and params structure' or should it store selected tests and test parameters in a dedicated structure and post it when controller requires? 该视图应该通过遍历表的所有行并检查参数来提供信息(因此没有专用的“选定的测试和参数结构”),还是应将选定的测试和测试参数存储在专用结构中,并在控制器需要时将其发布?

Or controller knows the view and it can grab all the data it needs from View? 还是控制器知道视图,并且它可以从View抓取它需要的所有数据?

I would expect the controller to have intimate knowledge of both the view and model. 我希望控制器对视图和模型都具有深入的了解。 So I prefer "...controller knows the view and it can grab all the data it needs from View", as it means you keep the most difficult part to test, the view, as simple as possible. 因此,我更喜欢“ ...控制器知道视图,并且它可以从视图中获取所需的所有数据”,因为这意味着您将最困难的部分(视图)保持得尽可能简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM