samedi 12 mars 2016

ember.js loop fails on version 2.4.1

I have the following code from tutorialpoint on ember 1.10. It works fine.

<!DOCTYPE html>
<html>
   <head>
      <title>Emberjs displaying list of items</title>
      <!-- CDN's-->
      <script src="http://ift.tt/1H1Z8nj"></script>
      <script src="http://ift.tt/13wBVXk"></script>
      <script src="http://ift.tt/1H1Z8Uo"></script>
      <script src="http://ift.tt/1LNmMn9"></script>
      <script src="http://ift.tt/1H1Z8nl"></script>
      <script src="http://ift.tt/1e1uqGJ"></script>
   </head>
   <body>
      <script type="text/x-handlebars">
         <ul>
           <!-- Getting each value of the myArray -->
            {{#each value in App.myArray}}
               <!-- diplaying the values -->
               <li>{{value}}</li>
            {{/each}}
         </ul>
      </script>

      <script type="text/javascript">
         var App = Ember.Application.create()
         //creating the array
         App.myArray = ['Mona','Manu','Mack']
      </script>
   </body>
</html>

However if I changed the version from

  <script src="http://ift.tt/1H1Z8Uo"></script>

to

  <script src="http://ift.tt/1TVkhVB"></script>

then the code stopped working with no error. My first question is how can I make it work under 2.4?

My second question is, even under version 1.1, if I use id="{{value}}" it won't work. How can I assign {{}} to DOM element id, like this?

<!DOCTYPE html>
<html>
   <head>
      <title>Emberjs displaying list of items</title>
      <!-- CDN's-->
      <script src="http://ift.tt/21nXWii"></script>
      <script src="http://ift.tt/1L6zqzP"></script>
      <script src="http://ift.tt/1H1Z8Uo"></script>
      <script src="http://ift.tt/1LNmMn9"></script>
      <script src="http://ift.tt/1H1Z8nl"></script>
      <script src="http://ift.tt/1e1uqGJ"></script>
   </head>
   <body>
      <script type="text/x-handlebars">
         <ul>
           <!-- Getting each value of the myArray -->
            {{#each value in App.myArray}}
               <!-- diplaying the values -->
               <li id="{{value}}">{{value}}</li>
            {{/each}}
         </ul>
      </script>

      <script type="text/javascript">
         var App = Ember.Application.create()
         //creating the array
         App.myArray = ['Mona','Manu','Mack']
      </script>
   </body>
</html>




Aucun commentaire:

Enregistrer un commentaire