代码之家  ›  专栏  ›  技术社区  ›  Vinodh Ramasubramanian

从服务器返回的访问数据

  •  3
  • Vinodh Ramasubramanian  · 技术社区  · 15 年前

    我希望访问从服务器返回的实际值。 getRowData 在对值应用unformat之后返回值。这会导致信息丢失。

    例如,如果一个双精度值四舍五入到小数点后两位,并且如果我想用从服务器返回的原始值(6个小数)填充要编辑的表单,则如何获取返回的值。

    例如:

    从服务器返回的值:12.345678

    列的格式化程序选项: formatter: 'number', formatoptions: {thousandsSeparator: ",", decimalPlaces: 2}

    网格显示值:12.35

    如何检索从服务器返回的值12.345678。 获取行数据 返回12.35

    我正在使用从服务器返回的json数据。使用firebug我已经确认服务器返回所有6个小数位。只有在从选定行检索值时,才会截断小数位数。

    1 回复  |  直到 15 年前
        1
  •  1
  •   Justin Ethier    15 年前

    你可以用 unformat 获取原始值,对于 getRowData 是的。有更多的信息在 Custom Formatter jqgrid wiki的部分。尤其包括以下示例:

    <script>
    jQuery("#grid_id").jqGrid({
    ...
       colModel: [ 
          ... 
          {name:'price', index:'price', width:60, align:"center", editable: true, formatter:currencyFmatter},
          ...
       ]
    ...
    });
    
    function currencyFmatter (cellvalue, options, rowObject)
    {
       // do something here
       return new_format_value
    }
    </script>
    

    因此,在您的unformatter中,您应该能够只获取原始值(小数点后两位以上)并返回它。