I am using Knockout a lot and often times I have to write scripts inside the data-bind attributes. Is there any validation tools that I can use on these markup files to validate the javascript inside data-bind
attributes? Would be nice if there is a grunt plugin.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
There probably isn't (a prominent) one, because it's not common to have a lot of complex logic inside your view. With MVVM-like approaches it works best if you keep the View rather plain, and write out logic in your ViewModel where you can unit test it.
So do not do this:
Instead, do this:
Because that would allow you to unit test the
shouldShowItem
logic, e.g. with QUnit:Bottom line, if you find yourself writing out lots of logic inside your view, you probably need to move some of it to your view models and make it testable.