jquery - AJAX 仅使用 jQuery 填充最终的 JSON 对象?也使用了 Circliful jQuery 插件

标签 jquery html css ajax

我有一个填充 ajax 请求的 JSON 文件,它检索数据但仅在每个 div 中显示来自 JSON 文件的最后一个对象值。

这里是小片段 - https://jsfiddle.net/cale_b/qxctuw47/

不确定我哪里出错了。

<div class="grid">
</div>
<!-- i've simplified the json in comparison to the jsfiddle -->
var data = [{
    "id": 1,
    "rating": "25",
  },
  {
    "id": 2,
    "rating": "30",
  }
];

jQuery(function($) {
  $.each(data, function(key, value) {
    var profile_data = '';
    // ... other code here
    profile_data += '<div class="grid-item grid-item--width3 grid-item--height3 myStat" data-animation="1" data-animationStep="3" data-percent="' + value.rating + '"></div>';
    // append each one within the each loop    
    $('.grid').append(profile_data);
  });
  $(".myStat").circliful({});
});

最佳答案

您只为所有具有 .myStats 类的元素创建一个 circliful 实例...

改为为每个实例创建一个实例:

$(".myStat").each(function(){
  $(this).circliful({});
});

你的 Fiddle updated

关于jquery - AJAX 仅使用 jQuery 填充最终的 JSON 对象?也使用了 Circliful jQuery 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57231490/

相关文章:

javascript - 如何在单击按钮后突出显示动态添加的 UL Li 元素 3-5 秒

javascript - Google Closure 中的变量

css - 如何使用 CSS 转换在屏幕上滑动 div?

css - 并排对齐2个div

javascript - 单击特定超链接时切换对象的可见性

javascript - ReactJS:如何不断检查本地存储中的 token 是否已过期?

Javascript 在 Firefox 中加载不正确

javascript - 日期天数间隔不应超过 20 天

PHP-REGEX - 多项选择类型

html - 从网页启动 Catia 并显示谁拥有许可证