简体   繁体   English

我正在尝试创建一个圆形进度条,但我无法访问 javascript 变量,为什么?

[英]I am trying to create a circle progress bar, but I can not access the javascript variables, why?

I am working with tailwind.css in my Django HTML template.我在我的 Django HTML 模板中使用 tailwind.css。 I am trying to recreate this circle https://tailwindcomponents.com/component/circular-progress-bar , but I am not rolling my screen, I am setting a static percentage based on a value from my view.我正在尝试重新创建这个圆圈https://tailwindcomponents.com/component/circular-progress-bar ,但我没有滚动屏幕,我根据我的观点设置了 static 百分比。

This average rate calculation does not matter, this is working in another part, it is just an example to show what I want to do in my radial bar.这个平均速率计算无关紧要,这在另一部分中起作用,它只是一个示例,用于显示我想在我的径向栏中执行的操作。

class RatePage(TemplateView):

template_name = "tailwind/rate-page.html"

def get_context_data(self, **kwargs):

    context = super(RatePage, self).get_context_data(**kwargs)

    context['average_rate'] = 4.5

    return context

This is my HTML template.这是我的 HTML 模板。

<div class="flex flex-col">
  Score

  <svg class="w-20 h-20">
    <circle
      class="text-gray-300"
      stroke-width="5"
      stroke="currentColor"
      fill="transparent"
      r="30"
      cx="40"
      cy="40"
    />
    <circle
      class="text-blue-600"
      stroke-width="5"
      :stroke-dasharray="circumference"
      :stroke-dashoffset="circumference - percent / 100 * circumference"
      stroke-linecap="round"
      stroke="currentColor"
      fill="transparent"
      r="30"
      cx="40"
      cy="40"
    />
  </svg>
  <span class="absolute text-xl text-blue-700" x-text=30></span>
</div>

<script>
  let percent = rate;
  let circumference = 2 * Math.PI * 30;
</script>

I am trying to connect JavaScript with the rate value from view to make this calculus.我正在尝试将 JavaScript 与视图中的速率值连接起来以进行此微积分。 But, everything I am getting is this:但是,我得到的一切都是这样的:

在此处输入图像描述

But, I am trying to do it:但是,我正在尝试这样做:

在此处输入图像描述

Any suggestion?有什么建议吗?

Ensure you are using the javascript content block确保您使用的是 javascript 内容块

{% block javascripts %}{% endblock javascripts %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM