我将从 API 获取的数据打印到表中,但将行数值固定为小数时遇到一些困难。如果 API 中的行数据由数值组成,即 等10.0, 333, 8 or 100
,则最终以十进制值呈现 -> 10.00, 333.00, 100.00
。
我熟悉的函数.toFixed(2)
在 React 中的运行方式与我以前在 javaScript 中编写它的方式不同。我认为我误导了 ES6 标准,但我不确定。如果我避免使用.toFixed(2)
.
这是我的代码示例rows.toFixed(2)
,但它的功能不佳:
class App extends React.Component
{
constructor()
{
super();
this.state = {
rows: [],
columns: []
}
}
componentDidMount()
{
fetch( "http://ickata.net/sag/api/staff/bonuses/" )
.then( function ( response )
{
return response.json();
} )
.then( data =>
{
this.setState( { rows: data.rows, columns: data.columns } );
} );
}
render()
{ …
Run Code Online (Sandbox Code Playgroud)