我需要将货币输出添加到 jQuery 函数中。因此,像 1577334.668 这样的数字将打印为 $1,577,335。我认为我应该在控制器中执行此操作,但我的老板今天告诉我我应该在 jQuery 视图中执行此任务,我只是不知道该怎么做。我在下面包含了 jQuery 代码,并在我需要打印货币金额的变量旁边添加了注释。该变量称为SC[i]
。任何意见或建议将不胜感激!谢谢你的帮助!
//Spend Category function for monthly
pa_click = function (pa_label) {
PA_ID = pa_label.getAttribute('pa_id');
var pa_details = document.getElementById('pa-details-' + PA_ID);
jQuery.getJSON('@Url.Action("getAjaxSCs")', { PA: pa_label.title }, function (SCS) {
pa_details.innerHTML = "";
jQuery.each(SCS, function (index, SC) {
months_html = '';
for (var i = 0; i < 12; i++) {
months_html +=
'<div id="SC-' + index + '-' + months[i] + '" class="month-wrapper tree border-white">' +
SC[i] + // This is the variable I need to replace with code to add currency to the amount
'</div>';
}
pa_details.innerHTML +=
'<div id ="Spend-Category-' + index + '" class="sc-wrapper tree border">' +
'<div id ="sc-title-' + index + '" class="sc-title">' +
'<div class = "sc-label" title = "' + index + '" SC_id="' + index + '" onclick = "sc_click(this)">' + index + '</div>' +
months_html +
'</div>' +
'<div id="sc-details-' + index + '" class = "pa-details" style = "display:none">' + index + '</div>' +
'</div>';
})
});
jQuery('#pa-details-' + PA_ID).show('slide', { direction: 'up' }, 'fast');
};