Recently in the framework of integrating the front end, we know that one of the most powerful templating engines of JavaScript is jsrender, the standard implementation of the next-generation jquery template engine.
Usually in the template merge process, we encounter two or even three levels of nesting situation, the powerful jsrender will naturally support, as follows:
<! DOCTYPE html> {{ for#data}} {{ forLanguage}} <li>{{: #parent. Parent.data.name}} is learning {: title}}<br/> {{ forscores}} <a href= "#" >{{:score}}</a> {{/for}} </li> {{/for}} </ul> {{ /for}}</script><script type= "Text/javascript" >varStudents = [{name: "Zhang San", Language:[{title: "Medium", Scores:[{score:12},{score:13},{score:14}]},{title: "English", Scores:[{score : 12},{score:13},{score:14}]},{title: "Number", scores:[{score:12},{score:13},{score:14}]}]}, {name:"John Doe", Language:[{title: "Zhong", Scores:[{score:12},{score:13},{score:14}]},{title: "Zhong", scores:[{score:12},{score:13}, {score:14}]},{title: "Medium", scores:[{score:12},{score:13},{score:14}]}]}, {name:"Harry", Language:[{title: "Zhong", Scores:[{score:12},{score:13},{score:14}]},{title: "Zhong", scores:[{score:12},{score:13}, {score:14}]},{title: "Medium", scores:[{score:12},{score:13},{score:14}]}]}]; $("#studentList"). HTML ($ ("#studentTemplate"). Render (students));</script></body>The effect is as follows:
JavaScript Template Library Jsrender for loop nesting example