当我在javaScript(JSLINK文件)中求数值时,我们得到了结果

时间:2017-05-16 00:00:47

标签: javascript jslink

我正在编写以下Javascript(JSLINK)来显示数值的总和,如下所示: -

var _totalValue1 = 0.0;
var _totalColumn = 27;  // Specify total number of columns in list view.
var _columnIndex1 = 14;  // Specify the index of the column where you want to display sum values. (i.e. index for first column = 1)
alert(101010);
function myCSRRendering1 () {

    var calculatedFieldCtx = {};  

    calculatedFieldCtx.Templates = {};

    calculatedFieldCtx.Templates.Fields = {
        "Yearof2017MLC": {
            "View": CalculatedFieldViewTemplate1
        }
    };
 SPClientTemplates.TemplateManager.RegisterTemplateOverrides(calculatedFieldCtx); 
    calculatedFieldCtx.OnPostRender = [];
    calculatedFieldCtx.OnPostRender.push(function()
    {  
        // Specify id of the list view table for which you want to display sum values. 
        var HTMLTableElement = document.getElementById("{B3D883A5-6962-47FD-BDEF-BB83FF4C78EA}-{C86BA145-8C22-47E8-938C-11B8C7F855C3}");

                var tbodyElement = document.createElement('thead');
                tbodyElement.id = "customAggWPQ";

                var trElement = document.createElement('tr');

                var tdElement;
                for(var i = 1; i <= _totalColumn; i++) {
                        tdElement = document.createElement('th');
                        tdElement.id = "tdElement" + i;
                        if( i == _columnIndex1) {
                              tdElement.innerHTML = "<b>Sum= " + numberFormat(_totalValue1) + "</b>";
                        }
                        trElement.appendChild(tdElement);
                }

        tbodyElement.appendChild(trElement);
        if(document.getElementById("customAggWPQ") == null) {
                HTMLTableElement.insertBefore(tbodyElement,HTMLTableElement.firstChild.nextSibling);
        }
        else {
                document.getElementById("tdElement" + _columnIndex1).innerHTML = "<b>Sum= " + numberFormat(_totalValue1) + "</b>";
        }
        _totalValue1 = 0.0;
    })

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(
        calculatedFieldCtx
    );

};


function CalculatedFieldViewTemplate1(ctx) {   

if(ctx.CurrentItem.Yearof2017MLC != "" ){
_totalValue1 += parseFloat((ctx.CurrentItem.Yearof2017MLC).replace(',', ''));
return ctx.CurrentItem.Yearof2017MLC;
}
  else
{
    return 0;
}


}
// register for MDS enabled sites
RegisterModuleInit('http://arqcvsps01/offices/resources/t10.js', myCSRRendering1);

// fallback for non-MDS enabled sites
myCSRRendering1(); 
var numberFormat = function(number) {


        return number;
};

现在我得到的结果是97.4456,而JSLINK显示97.44560000000001 ..这是我的表: -

enter image description here

所以有人可以就此提出建议吗?

0 个答案:

没有答案