我希望有<Input>过滤器组件作为可重用的组件。因此,不是:
// list.js
<Filter {...props}>
<TextInput source="abc" />
<SelectInput source="foo" choices={[
{ id: 'bar', name: 'bar' },
{ id: 'baz', name: 'baz' },
]}/>
</Filter>我想要:
// my-select-input.js
export const MySelectInput = props => (
<SelectInput source="foo" choices={[
{ id: 'bar', name: 'bar' },
{ id: 'baz', name: 'baz' },
]}/>
)// list.js
<Filter {...props}>
<TextInput source="abc" />
<MySelectInput />
</Filter>不幸的是,导出组件在过滤器工具栏中的位置与其他“正常”输入组件不同。我怀疑它得到了装饰,因为它将是“正常”的输入组件。
发布于 2021-01-28 07:14:54
React-admin的<Filter>内省其子级以构建筛选器名称列表。如果其中一个子节点没有source (或者没有label),那么它将不能在filters下拉菜单中列出它。
将源设置为defaultProps的修复。
// my-select-input.js
export const MySelectInput = props => (
<SelectInput source="foo" choices={[
{ id: 'bar', name: 'bar' },
{ id: 'baz', name: 'baz' },
]}/>
)
+MySelectInput.defaultProps = {
+ source: "foo",
+};https://stackoverflow.com/questions/65826913
复制相似问题