Introduction
I encountered a problem today. This problem is also a problem I encountered before. The previous method is also used by most people. You can read my article.
Previous Method--I guess this is also the way most people use it.
For example, the following code is taken from a piece of js Code on the Sina homepage. This method is also used by most people.
What did you do after reading the above Code? You may change the form of + = to the push form of the array. Some people say that push is faster than this character link, but it is not much faster.
If the embeddedHtmlThere are a lot of code. do you want to handle it like this? If you modify (add or delete)HtmlSo you need to constantly flip the code, find the corresponding tag, and then find the end tag. Do you not feel the trouble? Some people may write like this (this is what I wrote earlier, and it is also my most used method ).
The above code is also very difficult to maintain. Many times, if a tag is added to the ui or the html structure is modified, it is a headache for me.
Page templated--New Method
I recently read facebook's js Code. By chance, I found that the following method looks good and I hope to share it with you.
View my index.html code
View my js Code
Today, I accidentally discovered that this method is more reasonable, because the for loop is too disturbing.
Maintain the precedingHtmlThe code is very easy.HtmlIt is easy to change the code structure.
Summary
The above code has many problems. Don't be surprised. This is just my simple version.
The current template only supports simple variable replacement, and many functions are not developed, such as the if tag and for tag. if you are interested, try it. if it is successful, let me know. If we can build an open-source framework similar to smarty, we can also make some contributions to the open-source business.
Recommendation
From Chuan Shan Jia