javascript - 如何格式化烧瓶动态表中的值
问题描述
我从 API 中提取数据,在 ETL 过程中,我将它们转换为没有任何格式的纯数字,以便可以执行公式。
但是,我希望数据在前端表中调用后显示转换为货币结果。
这是动态表渲染:
<!-- Equity Holdings Performance Table -->
<table class="table table-hover table-striped table-sm">
<tr>
<th>ID</th>
<th>Trade Date</th>
<th>Price Gain</th>
</tr>
{% for row in all_equity_data_html %}
<tr>
<td>{{row.equity_id}}</td>
<td>{{row.equity_date_purchase}}</td>
<td> $ {{row.equity_price_gain}}</td>
</tr>
{% endfor %}
</table>
这是适用于一个字段但不适用于动态表的转换脚本:
<script>const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2
})
formatter.format(row.equity_price_gain)
</script>
<script>
$(document).ready( function() {
$("td.equity_price_gain").each(function() { $(this).html(parseFloat($(this).text()).toLocaleString('en-US', {style: 'currency', currency: 'USD'})); })
})
</script>
如何修复以下脚本?(我确实尝试了两种变体,看看我是否可以通过另一种方式获得它)
解决方案
推荐阅读
- c# - 更新 HttpWebRequest 中的 api 时出现错误请求
- ionic-framework - 使用 Ionic core 4 时不会显示 ion-content
- apache2 - apache2 virtual 无法正常工作,重定向到 000-default.conf 位置
- regular-language - 如何显示常规语言等于另一种语言?
- html - 如何在我的容器中对齐引导导航栏
- php - 如何使用php替换文件中的字符串
- demandware - 我们如何从 SFCC(需求软件)获取最后访问的管道。
- python - 如何解决 Python Pandas DataFrame 的“超出纳秒时间戳”错误?
- python - 如何在python中对LCSS使用递归
- php - 找不到 Php 致命错误类