gpt4 book ai didi

javascript - 在表标题中加载 JSON 数据

转载 作者:行者123 更新时间:2023-12-01 03:54:29 24 4
gpt4 key购买 nike

我在表标题中加载 JSON 数据时遇到问题。在我的函数 loadJSON 中,我正在加载对象的注释,如下所示:

<tr title="this['achievementlist'][i].comment"></tr>

结果是: link of picture

当我删除“.”时,评论会被加载,但只有第一个单词。阅读后:HTML title attribute in Rails displaying only first word我重新添加了 "。从逻辑上讲,这又导致了 link of picture

如何将对象“achievementlist”的 JSON 注释作为标题加载?

JSON 数据:

{
"gijs":[
{
"name": "gijs",
"walletpoints": "5",
"totalpoints": "5",
"achievementlist":[
{
"achievementname": "een comaan",
"points": "50",
"comment": "werkt voor geen meter en ziet er niet uit"
},
{
"achievementname": "meer dan 5 huisdieren",
"points": "40",
"comment": "allemaal muizen in de kelder"
}
}

我的所有 html 代码:

<table>
<tr>
<td class="achievements"></td>
<script>
$.getJSON("../json/package.json", function (data)
{
$.each(data.gijs, function ()
{
for (var i=0; i<this['achievementlist'].length; i++)
{
$(".achievements").append("<tr title="+"this['achievementlist'][i].comment" +" class='tablerow'><td class='JSONDATA'><div class='JSONName'>" + this['achievementlist'][i].achievementname + "</div><div class='JSONPoints'>Points: " + "<strong>"+this['achievementlist'][i].points+"</strong>" + "</div></td></tr>");
}
});
});
</script>
</tr>
</table>

最佳答案

var data = {
"gijs":[
{
"name": "gijs",
"walletpoints": "5",
"totalpoints": "5",
"achievementlist":[
{
"achievementname": "een comaan",
"points": "50",
"comment": "werkt voor geen meter en ziet er niet uit"
},
{
"achievementname": "meer dan 5 huisdieren",
"points": "40",
"comment": "allemaal muizen in de kelder"
}]
}]
}

$.each(data.gijs, function (){
for (var i=0; i<this['achievementlist'].length; i++){
$(".achievements").append('<tr title="'+this['achievementlist'][i].comment+'" class="tablerow"><td class="JSONDATA"><div class="JSONName">'+ this['achievementlist'][i].achievementname + '</div><div class="JSONPoints">Points <strong>'+this['achievementlist'][i].points+'</strong></div></td></tr>');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td class="achievements"></td>
</tr>
</table>

关于javascript - 在表标题中加载 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42887094/

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