是否可以在消息和标题中引用除 id 字段之外的其他字段?

问题描述 投票:0回答:2

我希望屏幕的标题以及删除确认消息使用与 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
2个回答
0
投票

在页眉中,您可以使用记录中的任何字段: 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


0
投票

对于任何正在寻找如何使用

DeleteWithConfirmButton
执行此操作的人,以下是您可以执行此操作的方法。

interface CustomDeleteWithConfirmationProps
  extends DeleteWithConfirmButtonProps {
  field?: string;
}

export default function CustomDeleteWithConfirmation({
  field,
  confirmTitle,
  ...rest
}: CustomDeleteWithConfirmationProps) {
  const record = useRecordContext();

  return (
    <DeleteWithConfirmButton
      confirmTitle={
        field ? `Delete ${record[field]}?` : confirmTitle
      }
      {...rest}
    />
  );
}

© www.soinside.com 2019 - 2024. All rights reserved.