【问题标题】:Is it possible to reference another field than the id field in messages and titles?是否可以在消息和标题中引用除 id 字段之外的另一个字段?
【发布时间】:2019-06-24 10:35:40
【问题描述】:

我希望屏幕的标题以及删除确认消息使用与 id 不同的字段来向用户识别记录,因为 id 格式不是很人性化。

我知道如何自定义消息和标题的文本。但是,在构造文本消息时,我不知道如何访问除 id 参数之外的其他字段。

这可能吗,还是我需要匿名消息以不包含对实际记录的引用?

This is an illustration of the delete message, where I'd like something nicer for the user, like eg. the e-mail of the employee to delete, instead of the random string that is the id value.

【问题讨论】:

    标签: react-admin


    【解决方案1】:

    在页眉中,您可以使用记录中的任何字段: https://marmelab.com/react-admin/Show.html#page-title

    const PostTitle = ({ record }) => {
        return <span>Post {record ? `"${record.title}"` : ''}</span>;
    };
    
    export const PostShow = (props) => (
        <Show title={<PostTitle />} {...props}>
            ...
        </Show>
    );
    

    在删除确认对话框中,现在不可能将 id 字段更改为另一个,在我看来这种可能性仅在开发中: https://github.com/marmelab/react-admin/blob/master/packages/ra-ui-materialui/src/button/DeleteWithConfirmButton.js

    【讨论】:

    • 你可以用你自己的替换组件:DeleteButton / DeleteWithConfirmButton。
    • 如果只是对话框,我可能会用不包含 id 的消息覆盖字典中的消息。只要我只从显示或编辑屏幕中删除,这应该提供足够的上下文。这确实意味着我将无法使用 ListItem 上的删除按钮,因为我喜欢避免误点击,这在列表视图中很容易。
    猜你喜欢
    • 1970-01-01
    • 2014-04-24
    • 1970-01-01
    • 1970-01-01
    • 2023-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    相关资源
    最近更新 更多