Concern about the data style manipulation on the view
So, I want to display some rules concatenated with AND or OR, and I want to add color to AND or OR like red, green etc.
Fruit = Apple AND Market = SuperMarket1
So how should I do this? I have following thoughts:
- To control the css by adding the css properties in repository or service class which handles the data access, which works but violates MVC design pattern.
- To manipulate the data in the View using something like the Helper class, but the pr开发者_JS百科oblem is the helper class has to parse the string to find the AND and it is possible that if AND is part of the rule. Even it is in rare case but it is still possible that if any rule contains the keyword and displays it incorrectly.
Any idea? Thanks in advance!
Just conditionally set a span with appropriately styled class on the element you want to color in the View. You can set helpers to do this and that, but often times people get so out of hand with helpers that they needlessly complicate the app....which is the opposite of the aim of MVC. Yes, it might violate the "strict" rules that MVC is supposed to follow. But step back and think about it.....is your environment REALLY big enough that you have to 100% strictly separate a minute amount of code and the presentation layer? Really? I've worked for Fortune 500's who don't stress that much.
The thing about MVC is that you can analyze it to death. It's great help to those of us who are building complex apps. But, there's an exception to EVERTHING. If you stress about these exceptions, you're not going to get anything done. Loosen the tie, man.
精彩评论