Pregunta

I am trying to render value from below Json using Jquery template for loop, but not getting any values out of Json. Below is my Json:

    {
   "CommentListClass":[
      {
         "Author":"Attis1",
         "CommentText":"Really goo"
      },
      {
         "Author":"joshar1",
         "CommentText":"My picture"
      },

    }

My Jquery template is:

<script type="text/x-jsrender" id="tempRecentComments">
              {{for List}}
                <div class="item">
                    <div class="item-content">
                       <h3>{{:CommentListClass.Author}}</h3>
                    </div>
               </div>
                 {{/for}}

                </script>
¿Fue útil?

Solución

Try this,

{{for CommentListClass}}
      <div class="item">
         <div class="item-content">
            <h3>{{:Author}}</h3>
         </div>
      </div>
{{/for}}

Use data like,

[{
   "CommentListClass": [{
       "Author": "Test",
       "CommentText": "Really goo"
   }, {
       "Author": "joshar1",
       "CommentText": "My picture"
   }]
}];

Test on jsviews

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top