HTML Templating with minimal javascript
  1. $('#myDiv').fillTemplate(myData) 
The jsRepeater makes it easy to fill HTML Templates with javascript objects e.g. data received from the server via AJAX
  1. <script> 
  2. var myData = {"Name" : "Google", "Type" : "Search Engine", "URL" : "www.google.com"}; 
  3. $('#template1').fillTemplate(myData); 
  4. </script> 
  5. <body> 
  6. <div id='template1'>${Name} is a ${Type} found at <a href='${URL}'>${URL}</a></div> 
  7. </body> 
results in:
Google is a Search Engine found at
This is the most basic example. The power of jsRepeater lies in the fact that it has support for some of the more complex functionality we need in the real world e.g.
Binding not only to an object but child objects in one template
Ability to write your own javascript functions for output formatting
Access to numbering in a loop
No need for alternating templates, alternation handled in markup, not only even and odd values but also first and last

Infinite recursion down an object graph in one template 

转载请注明:代码家园 » jsRepeater