如何在 admin-on-rest reactJS 中更改字段源
How to change field source in admin-on-rest reactJS
我有状态字段,值为0 and 1
,属性类型是整数,但我需要显示为字符串/转换为单词,其中 1 是 "accepted",0 是 "rejected" .
如何在 <TextField source="status" />
中更改它?
你应该write your own component
。请参阅下面的示例
import React, { PropTypes } from 'react';
const CustomTextField = ({ source, record = {} }) => <span>{ (record[source] === 1) ? 'accepted' : 'rejected' }</span>;
CustomTextField.propTypes = {
label: PropTypes.string,
record: PropTypes.object,
source: PropTypes.string.isRequired,
};
export default CustomTextField;
我有状态字段,值为0 and 1
,属性类型是整数,但我需要显示为字符串/转换为单词,其中 1 是 "accepted",0 是 "rejected" .
如何在 <TextField source="status" />
中更改它?
你应该write your own component
。请参阅下面的示例
import React, { PropTypes } from 'react';
const CustomTextField = ({ source, record = {} }) => <span>{ (record[source] === 1) ? 'accepted' : 'rejected' }</span>;
CustomTextField.propTypes = {
label: PropTypes.string,
record: PropTypes.object,
source: PropTypes.string.isRequired,
};
export default CustomTextField;