我以前有这样的要求:
let data = {
chartLibraryType : this.state.chartCategory == 'highChart'? "HIGH_CHARTS" : "C3",
};
现在我需要用3来实现。除了highcharts和c3之外,我还需要传递d3。
let data = {
chartLibraryType : if(this.state.chartCategory == 'highChart'){
"HIGH_CHARTS"
}else if(this.state.chartCategory == 'c3Chart'){
"C3"
}else if(this.state.chartCategory == 'D3Chart'){
"D3"
},
};
当我们有两个以上时,这是实现的方法吗?
首先,您可以创建一个dictionary
。
let dictionary={
"highChart" : "HIGH_CHARTS",
"c3Chart" : "C3",
"D3Chart" : "D3"
}
然后,您必须使用表示法将状态作为字典的键进行传递bracket
。
let data = {
chartLibraryType : dictionary[this.state.chartCategory]
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句