DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • Show a List in a Template
  • / On this page
    • Show a List in a Template

      page
      • source

      To make an Array observable, pass it to can.List.

      var people = new can.List([
          {firstname: "John", lastname: "Doe"},
          {firstname: "Emily", lastname: "Dickinson"}
      ]);
      
      var frag = can.view("app-template", {people: people})
      $("#my-app").html(frag);
      

      To show a list of data within a stache template, use the #each operator.

      <ul>
      {{#each people}}
        <li>
          {{lastname}}, {{firstname}}
        </li>
      {{/each}}
      </ul>
      

      Inside the #each block, the attributes are scoped to individual objects in the list of people.

      To make changes to the list, use an Array method such as push or pop.

      // adds a new person
      people.push({firstname: "Paul", lastname: "Newman"})
      // removes the last person
      people.pop()
      

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.