问题
I'd like to find out about libraries with the following properties:
- Javascript implementation for client-side,
- Java implementation for server-side,
- light-weight syntax: no generic 'code', only simple expressions,
- but simple for-loops, 'include', and 'if'.
(In short, the syntax would be similar to Django templates, if that tells you anything.)
Does anybody know an open-source library that fulfills these requirements?
回答1:
Have you considered using Mustache? It offers very simple templates and can be used in both java and javascript.
If you look at the docs you can see simple examples of loops:
{{#names}}
Hi {{name}}!
{{/names}}
and conditions:
{{#value}}
Value was true
{{/value}}
{{^value}}
Value was false
{{/value}}
Includes can be handled by using partials, which let you pull in another template.
来源:https://stackoverflow.com/questions/13349082/javascript-java-html-template-data-binding-library