python - 将 python 列表从上下文传递给 JS 函数
问题描述
我有一个视图,可以为每个国家/地区呈现数据字典,如下所示:
def InvoicingDashboardView(request):
# For reference - "c" is the context dictionary, and it's already initialized by this point
for client in Client.objects.all():
fte = frame.fte(c['start_date'], c['end_date'], time = 'external', client = client.id)
if fte > 0:
c['countrys'][client] = {
'name': client.name,
'fte': fte,
'var_fte': fte - frame.fte(c['var_start_date'], c['var_end_date'], client = client.id),
'daily_ftes': [frame.fte(day, day) for day in c['label_days']],
}
return render(request, 'dashboards/invoicing.html', context = c)
正如你所看到的,例如,如果我打电话{{countrys.client.fte}}
给那个客户,我会得到 fte。
到目前为止一切都很好,但我需要daily_ftes
一个 JS 函数,如下所示:
<div class="dash_countrys_ftes">
{% for country, items in countrys.items %}
<div class="dash_country_block">
{% with name=items.name fte=items.fte variation=items.var_fte flag=country.flag.url %}
{% include 'dashboards/charts/country_block.html' %}
{% endwith %}
</div>
<script>
countryFteVariation("{{items.daily_ftes|escapejs}}") // HERE
</script>
{% endfor %}
</div>
问题是这daily_ftes
是一个python列表。
为了让 javascript 将其读取为列表而不是字符串,我可以在这里做什么?
解决方案
推荐阅读
- jmeter - 从 JMeter 中的 JSON 响应中选择随机名称
- arrays - 在bash中返回数组的函数
- python - 如何根据特定的列值将数据框过滤成 2?
- ruby-on-rails - 如何编写 jmeter 测试以在网站内提交表单(Jmeter,ruby -jmeter)
- javascript - 使用 value = "" 编辑表单以更新 JSON 文件 ng-model 不起作用
- python - Python3.8 通用线程错误“异常在由...启动的线程中被忽略”
- flutter - 颤振 | Gradle 在从网络下载工件时抛出错误。正在重新下载
- javascript - 将时刻转换为 ISO 格式的 JS 日期
- c# - System.Diagnostics.Process 在使用 Process.UseShellExecute=false 时锁定文件
- mysql - MariaDB 显示警告而不是错误