开发者

How to generalize view?

开发者 https://www.devze.com 2022-12-30 20:33 出处:网络
Hey guys, I\'m in the process of designing a set of views that use the same model in my app, th开发者_如何学运维e difference is that some views will differ in Read Only and Modifiable fields.

Hey guys, I'm in the process of designing a set of views that use the same model in my app, th开发者_如何学运维e difference is that some views will differ in Read Only and Modifiable fields.

So for example for view A I want to be able to modify A.One but no A.Two properties and for view B I want to have B.One and B.Two as modifiable fields.

I was thinking in having a map that will hold this information and iterate both the modifiable and non-modifiable lists in a generic view, but I was thinking that maybe I can get feedback from you guys.

What do you think?


I have found that typically you are better off just sticking with having multiple views. There is some duplication but it simplifies things greatly. For example, the decision of whether to be in "view" mode or "edit" mode really belongs in the controller. Also, because views are not easily unit tested, you want to have as little logic in them as possible.

0

精彩评论

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