react-admin - 基于相关记录字段的 React Admin Change 字段
问题描述
假设我有一个名为“资产”的记录,其中有一列名为 deducitble。一项资产可以有一个保险公司。保险公司有一个布尔字段“allowOtherDeductible”。
编辑资产时,我希望能够首先检查关联保险公司是否将 allowOtherDeductible 设置为 true。如果是这样,我将允许一个 TextInput 用于deductible,如果为 false,则允许一个 SelectInput。
我怎样才能做到这一点?在有条件地呈现字段时,我看不到获取相关记录字段的方法。
解决方案
我会编写一个自定义输入,利用将其SimpleForm
注入record
所有孩子的事实:
const DeductibleInput = ({ record }) => {
if (!record) return null;
const { data, loaded } = useGetOne('insurers', record.insured_id);
if (!loaded) return null; // or a loader component
return data.otherDeductible
? <NumberInput
source="deductible"
parse={val => dollarsToCents(val)}
format={val => centsToDollars(val)}
/>
: <SelectInput
source="deductible"
parse={val => dollarsToCents(val)}
format={val => centsToDollars(val)}
choices={getDeductibleChoices(record.insured_value)}
/>
}
推荐阅读
- sqlite - 在 sqlite 中将列更改为主键
- python - 如何在纯文本字符串中屏蔽部分电子邮件地址以隐藏用户详细信息
- amazon-web-services - 在 AWS ELB 的目标组中添加 RDS 作为侦听器
- jmeter - 如何知道jmeter中请求的服务器处理时间是多少?
- python - 机器学习 - 分类问题
- flutter - 获取列表中最受欢迎的值
- python - 如何在邮递员中获取我要查询的特定标签的标题?
- r - R中的线密度热图
- java - 从 oracle 数据库获取表的元数据(所有表名)并将其存储在 java arraylist 中的有效方法
- search-engine - Rocchio 算法在什么向量空间中计算?