Javascript 如果this.props.myVar=='';某物';不起作用
我有以下资料:Javascript 如果this.props.myVar=='';某物';不起作用,javascript,reactjs,object,Javascript,Reactjs,Object,我有以下资料: var chartOptions = { scales: { yAxes: [{ ticks: { callback: (v) => { if (v < 3600000) { return this.callFormat(v)
var chartOptions = {
scales: {
yAxes: [{
ticks: {
callback: (v) => {
if (v < 3600000) {
return this.callFormat(v)
}
},
stepSize: (this.props.mode == 'calls' ? 7200 : 1000)
}
}]
}
};
也不起作用
家长
...
<div className="col-xs-6">
{!this.state.chart_loading ? <Chart data={this.state.chart_data}
mode={this.state.stat_view}/> : null}
</div>
...
。。。
{!this.state.chart\正在加载?:null}
...
Chart.js
import React, {Component, PropTypes} from 'react';
import {Line as LineChart} from 'react-chartjs-2';
import Numeral from 'numeral';
export default class Chart extends Component {
constructor(props, context) {
super(props);
}
callFormat(seconds) {
var time = Numeral(seconds).format('00:00:00');
var bits = time.split(':');
var str = '';
if (bits[0] > 0) {
str += bits[0] + 'h';
}
if (bits[1] > 0) {
if (bits[1] < 10 && bits[0] == 0) {
str = bits[1].substr(1, 1) + 'm';
} else {
str += ' ' + bits[1] + 'm';
}
}
if (bits[0] == 0 && bits[1] == 0) {
str = 0;
}
return str;
}
render() {
if (this.props.mode == 'calls') {
var stepSize = 7200
}
var chartOptions = {
scales: {
yAxes: [{
ticks: {
callback: (v) => {
if (v < 3600000) {
return this.callFormat(v)
}
},
stepSize
}
}]
}
};
return (
<LineChart data={this.props.data} options={chartOptions} width={950} height={250}/>
);
}
}
import React,{Component,PropTypes}来自'React';
从'react-chartjs-2'导入{Line as LineChart};
从“数字”中导入数字;
导出默认类图表扩展组件{
构造函数(道具、上下文){
超级(道具);
}
呼叫格式(秒){
变量时间=数字(秒)。格式('00:00:00');
变量位=时间分割(':');
var-str='';
如果(位[0]>0){
str+=位[0]+'h';
}
如果(位[1]>0){
if(位[1]<10&&bits[0]==0){
str=位[1]。substr(1,1)+'m';
}否则{
str+=''+位[1]+'m';
}
}
如果(位[0]==0和位[1]==0){
str=0;
}
返回str;
}
render(){
if(this.props.mode=='calls'){
var步长=7200
}
var图表选项={
比例:{
雅克斯:[{
滴答声:{
回调:(v)=>{
如果(v<3600000){
返回此.callFormat(v)
}
},
步长
}
}]
}
};
返回(
);
}
}
如果你能告诉我如何使用这个组件,那就太好了。我已经添加了更多信息。你能告诉我你是如何将mode prop传入的吗?/该prop的设置是什么吗?它来自:{!this.state.chart\u load?:null}我已经在chart.js的呈现中登录了控制台,它应该是这样的,这就是为什么我不明白为什么逻辑不起作用。
import React, {Component, PropTypes} from 'react';
import {Line as LineChart} from 'react-chartjs-2';
import Numeral from 'numeral';
export default class Chart extends Component {
constructor(props, context) {
super(props);
}
callFormat(seconds) {
var time = Numeral(seconds).format('00:00:00');
var bits = time.split(':');
var str = '';
if (bits[0] > 0) {
str += bits[0] + 'h';
}
if (bits[1] > 0) {
if (bits[1] < 10 && bits[0] == 0) {
str = bits[1].substr(1, 1) + 'm';
} else {
str += ' ' + bits[1] + 'm';
}
}
if (bits[0] == 0 && bits[1] == 0) {
str = 0;
}
return str;
}
render() {
if (this.props.mode == 'calls') {
var stepSize = 7200
}
var chartOptions = {
scales: {
yAxes: [{
ticks: {
callback: (v) => {
if (v < 3600000) {
return this.callFormat(v)
}
},
stepSize
}
}]
}
};
return (
<LineChart data={this.props.data} options={chartOptions} width={950} height={250}/>
);
}
}