MVC 和模型集合
我是一个模式新手,所以如果这个问题听起来太愚蠢,请原谅。 我正在对一个应用程序进行建模,该应用程序需要一个名为 CityData 的相同结构列表,并且一次只能显示其中一个结构。该视图将允许用户在各种 CityData 之间滚动。
现在我的问题是:我应该有一个模型,包含 CityData 列表和当前显示的索引,还是应该 CityData 是模型,并且它的列表应该包含在控制器中,控制器又会处理视图中的事件并更新当前显示的项目?
我会选择第一个,但是将当前显示的索引信息保留在模型中的想法对我来说听起来并不完全正确......
I am a patterns newbie so please excuse this question if it sounds too silly.
I am modelling an application which requires a list of identical structures, named CityData, and only one of these structures should be displayed at a time. The view will allow the user to scroll among the various CityData.
Now my problem is: should I have a single model, containing a CityData list and the current displayed index, or should CityData be the model, and a list of it should be included into the controller, which in turn would handle events from the view and update the current displayed item?
I would go for the first one, but the idea of keeping the current displayed index information inside the model just doesn't sound completely correct to me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何将列表保留在模型中,而将当前查看的项目的索引保留在控制器中。按顺序,控制器会询问模型有多少个 CityData 对象可用,然后获取第一个 CityData 对象并让视图显示该对象。然后,控制器可以处理用户查看其他 CityData 对象的请求,从模型中获取它们,然后让视图显示它们。
How about keeping the list in the Model but the Index of the currently viewed item in the Controller. In sequence the controller would ask the Model how many CityData objects are available, then get the first CityData object and let the View show the object. The Controller can then handle requests from the user to view other CityData objects, getting them from the Model and in turn letting the View display them.