Today it is fashionable to store HTML in JavaScript? MVC already invented?

0 like 0 dislike
7 views
Hello!

Have not written the JavaScript but nothing serious.
I see a very well developed frameworks.

Tell me how to solve the problem HTML? For example, when you dynamically based on JSON'and coming from the server side, complex HTML code? It is clear that it is possible to put HTML code on the server side, and can and hands DOM to assemble. But in the first case you are tied to the data format, the second sometimes very complex work structure, and to change numerous addChild in case of major changes in the code difficult. For this there are templates on the server side. But clientsthe what is now the most labor?
by | 7 views

7 Answers

0 like 0 dislike
by
0 like 0 dislike
closure templates is very suggest. Working in several military projects. Hosted on code.google.com the exact link can give when at the computer I will :-)
by
0 like 0 dislike
there are also XML+XSLT
by
0 like 0 dislike
I also often face this issue.
chose for himself three approaches:
\r
1. if you wish to generate a little code, something itrade a text box with the label, using jquery: $("...).after(...). Convenient because you can brashirovanie links to the items, which are then hung obrabotkami events, etc.
\r
2. structure can be a little more complicated, but not much, to complain about $.nano is an excellent plugin and very small. I even like how it is written. However there are limitations — the arrays of values, but
\r
3. If big data is to render a go between the client and the server, I've been here the entire HTML generated on the server, and then it is inserted. The fact that I believe that the site still needs to be able to work without JS (this is a separate question — why). So if JS for some reason doesn't work comes a normal page. The server decides, depending on ajax or naaah the request comes and gives either full page or piece. By the way, helps ajaxify jquery plugin
by
0 like 0 dislike
I do not recommend to use xml+xslt all browsers on a miscellaneous perceive it.
Tested on my own skin. It is very hard to debug errors.
by
0 like 0 dislike
Just finished a big project, which for such purposes used EJS (openarena javascript template library). You can make templates with quite sophisticated logic.
by
0 like 0 dislike
My advice to You is not wise with template engines for JS. If it is necessary for the template to propagate a piece of code, for example, for the table data — make it hidden class template. Tags, which are necessary to substitute the values also provide the relevant classes, for example: cell-name cell-price, etc. and substitute in them the values. This way you kill several birds with one stone (the substitution of values, the definition of handlers, convenient debugging, etc.) using simple tools.
by

Related questions

0 like 0 dislike
3 answers
0 like 0 dislike
3 answers
0 like 0 dislike
7 answers
110,608 questions
257,186 answers
0 comments
28,647 users