gpt4 book ai didi

javascript - 使用 Jquery 模板 For 循环读取 Json

转载 作者:行者123 更新时间:2023-11-30 17:30:40 25 4
gpt4 key购买 nike

我正在尝试使用 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>

最佳答案

试试这个,

{{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

关于javascript - 使用 Jquery 模板 For 循环读取 Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23131385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com