【发布时间】:2017-05-24 20:29:10
【问题描述】:
在下面的代码中,我只想为chartDesc 设置一些字词的样式(例如“投资回收期”)。粗体或斜体等。尝试了正则表达式,没有用。请帮忙!
import React from 'react';
import Pie from './Pie';
import TextTruncate from 'react-text-truncate';
import ReactTooltip from 'react-tooltip';
import { browserHistory } from 'react-router';
export default class Donutchart extends React.Component {
constructor(props) {
super();
}
getElements(id) {
let backendData = this.props.data;
let width = 120;
let height = 120;
let radius = Math.min(width, height) / 2;
let donutWidth = 15;
let chartData;
let chartDesc;
switch(id) {
case 'CASH_PURCHASE' :{
chartData = backendData["financialModelToFinancialSummary"][id];
const chartDescValue = backendData["financialModelToFinancialSummary"][id];
chartDesc = `Your estimated Solar Savings over 25 years (after net costs) will be $ ${parseFloat(chartDescValue.savings).toFixed(0)}, the payback period will be ${chartData["roiYear"]} years, and your home will increase in value by $ ${parseFloat(chartDescValue.increaseHomeValue).toFixed(0)}`;
break;
}
【问题讨论】:
-
您在何处以及如何显示 chartDesc。你能控制它的显示吗?
-
你的渲染函数在哪里?你能把它包括进来吗
-
下面是TextTruncate标签下的渲染函数
<TextTruncate line={2} truncateText="…" text={chartDesc} textTruncateChild={<a style={{color: chartData.uiData.color}} onClick={this.onDetailClick.bind(this,id)}>more..</a>} />