简体   繁体   English

在reactjs中将字符串转换为整数

[英]Convert string to integer in reactjs

if(this.state.chartCategory == 'D3Chart'){
      console.log("chartdata for d3 charts", this.state.d3line.chartData);

        switch(this.state.chartType){
          case 'area': return <div  style={{width: 900, height:300}}><Areagraph  data = {this.state.d3line.chartData} vars = {{x: this.state.d3line.x, y: this.state.d3line.y}} dispatch = {this.showFilter} title = {this.state.data.chartName}/></div>;
          case 'pie': return  <div style={{width: 900, height:500}}><Piegraph  data = {this.state.d3line.chartData} vars = {{x: this.state.d3line.x, y: this.state.d3line.y}} dispatch = {this.showFilter} title = {this.state.data.chartName}/></div>;
          case 'bar': return  <div  style={{width: 900, height:300}}><Bargraph  data = {this.state.d3line.chartData} vars = {{x: this.state.d3line.x, y: this.state.d3line.y}} dispatch = {this.showFilter} title = {this.state.data.chartName}/></div>;
          /*case 'column': return  <div className = "graphContainer" style={{width: 900, height:300, overflow: "hidden", resize: "both", paddingBottom: "10px", border: "1px solid black"}}><Columngraph  data = {this.state.d3line.chartData} vars = {{x: this.state.d3line.x, y: this.state.d3line.y}} dispatch = {this.showFilter} title = {this.state.data.chartName}/></div>;*/
          case 'line' : return <div  style={{width: 900, height:300}}><Linegraph  data = {this.state.d3line.chartData} vars = {{x:this.state.d3line.x, y: this.state.d3line.y, group: this.state.d3line.x}} dispatch = {this.showFilter} title = {this.state.data.chartName}/></div>;
          default: return null;
       }   

    }

In the console I am printing the data which i want to convert from string to integer If number, convert string to integer, number also taking as string, How to convert into number need to remove " "在控制台中,我正在打印我想从字符串转换为整数的数据如果是数字,将字符串转换为整数,数字也作为字符串,如何转换为数字需要删除“”

If you check in the picture I need to convert, if it a number alone如果你签入我需要转换的图片,如果它是一个数字

I'm not really sure if this really is different using ReactJs, but did you try to parseInt() the strings?我不确定使用 ReactJs 是否真的不同,但是您是否尝试过 parseInt() 字符串?

I'm not really understanding what you are trying to do, but the most simple way for type-conversion would be the native functions of Javascript!?我不太明白您要做什么,但最简单的类型转换方法是 Javascript 的本机函数!?

https://www.w3schools.com/jsref/jsref_parseint.asp https://www.w3schools.com/jsref/jsref_parseint.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM