【问题标题】:Read Json using Jquery template For loop使用 Jquery 模板 For 循环读取 Json
【发布时间】:2014-06-01 14:54:31
【问题描述】:

我正在尝试使用 Jquery 模板循环从 Json 下面呈现值,但没有从 Json 中获取任何值。下面是我的 Json:

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

    }

我的 Jquery 模板是:

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

                </script>

【问题讨论】:

  • 看起来您使用的是 JsRender,而不是 jQuery 模板。您可以更改标题/文本这样说,并用 jsrender 过滤器替换您的 jquery-templates 过滤器吗?

标签: javascript jquery json templates jquery-templates


【解决方案1】:

试试这个,

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

使用类似的数据,

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

jsviews上测试

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-18
    • 2013-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-25
    • 2012-01-07
    • 1970-01-01
    相关资源
    最近更新 更多