Foreword
JsRender is a JavaScript template engine based on jQuery. It has the following characteristics:
· Simple and intuitive
· Powerful functions
· Extensible
· Fast as lightning
These features look very powerful, but almost every template engine will promote them like this. . .
Due to work needs, Xiaocai came into contact with this template engine. After using it for a while, I found that it is indeed relatively powerful, but Xiaocai feels that some parts are too powerful, which makes it difficult to understand.
On the other hand, the official documentation of JsRender is relatively detailed, but there is surprisingly little other information. If you encounter any problems, you basically can’t find them. Not only can’t you find related issues, but there are almost no results.
In addition, some parts of JsRender are really difficult to understand, so Xiaocai urgently needs to share some "best practices".
Based on recent use, Xiaocai has summarized some practical experiences. Of course, these experiences cannot be found in official documents.
Note: This article is not a basic introductory tutorial. The following examples have their own annotations. No excessive explanation is given. Readers can experience it by themselves. If you don’t understand, you can leave a message.
Nested loops use #parent to access parent data (not recommended)
序号 | 姓名 | 家庭成员 |
---|
Nested loops use parameters to access parent data (recommended)
Use else in custom tag (strongly not recommended)
名称 | 单价 |
---|
Copy code