我不知道如何根据传递的数据以不同的方式合并数据。这是道具数据....
columns={[
{
name: "Fund Name", //Title
width: "40%", //Colum Width
options: {[
customBodyRender: (value, tableMeta, updateValue) => {
var splitValue = value.split("//");
return (
<div className="fundName">{splitValue[0]}<p>{splitValue[1]}</p></div>
);
}
]}
}, {
name: "Review Date",
width: "20%"
}, {
name: "Company Debt",
width: "20%"
}, {
name: "Alerts",
width: "10%",
options: {[
simpleBodyRender: <Options />
]}
}
}
因此,如果它使用customBodyRender
我希望它做一件事并且如果它正在做simpleBodyRender
我希望它做的事情略有不同。
这里是合并
let columns = this.props.columns.map(item => {
item.options
? ({ ...item, options: eval(item.options) })
: item
});
基本上我希望它看起来更像这样......
let columns = this.props.columns.map(item => {
if(item.options == "customBodyRenderer"){
item.options
? ({ ...item, options: eval(item.options) })
: item
});
} else if(item.options == "simpleBodyRenderer"){
item.options
? ({ ...item, options: customBodyRender: (value, tableMeta, updateValue) => { eval(item.options) }})
: item
});
}
});
因此,如果是它,customBodyRenderer
它会打印所有内容,但如果是它,simpleBodyRenderer
它会为用户填写customBodyRender: (value, tableMeta, updateValue) => {
。
我希望这是有道理的。
谢谢