- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
仅当记录具有特定属性时,我才想在 TabbedShowLayout
中显示一个 Tab
。我尝试创建一个自定义组件,如下所示:
const EventsTab = ({...props, record}) => {
return record && record.hasEvents &&
<Tab label="Tab2">
test
</Tab>
}
然后将其添加到 Show
布局中:
<Show {...props}>
<TabbedShowLayout>
<Tab label="Tab1">
<MetricsComp {...props} />
</Tab>
<EventsTab {...props}/>
</TabbedShowLayout>
</Show>
但我收到以下错误:uncaught at finalize Invariant Violation: EventsTab(...): 必须返回有效的 React 元素(或 null)。您可能返回了未定义、数组或其他一些无效对象。
Admin-on-rest
允许有条件地呈现组件(如 How to access record's internals in Show/Edit/Create )但不允许 Tab
。有什么解决方法吗?
最佳答案
我们必须做类似的事情 - 不幸的是,我们无法访问 Show
中的记录,但我们可以访问 TabbedShowLayout
。所以我们决定创建一个自定义的 TabbedShowLayout
,其中 TabbedShowLayout
的 render() 改变如下:
render() {
const {
children,
contentContainerStyle,
record,
resource,
basePath,
translate,
version,
} = this.props;
let changedChildren = children;
if (record.excludeTab) {
changedChildren = [];
for (let i=0; i<children.length; i++) {
if (children[i] instanceof Array) {
changedChildren.push(children[i]);
} else if (children[i] instanceof Object
&& children[i].props.label !== "TabToExcludeLabel") {
changedChildren.push(children[i]);
}
}
}
return (
<div style={divStyle} key={version}>
<Tabs
value={this.state.value}
onChange={this.handleChange}
contentContainerStyle={contentContainerStyle}
>
{React.Children.map(
changedChildren,
(tab, index) => ....
)
}
关于admin-on-rest - TabbedShowLayout/TabbedForm 中的条件 Tab/FormTab 渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47287764/
当未聚焦的选项卡出现验证错误时,选项卡标题应显示为红色。取而代之的是,当未聚焦的选项卡出现验证错误时,选项卡标题不会给出任何错误指示。 当我使用子组件时会发生此问题。如果所有组件都在创建/编辑级别定义
有没有办法在使用 TabbedForm 时有条件地删除特定选项卡中的提交按钮(工具栏)? ( react 管理员) 最佳答案 这是我使用自定义工具栏的方法: }>... 工具栏看起来像这样: cons
仅当记录具有特定属性时,我才想在 TabbedShowLayout 中显示一个 Tab。我尝试创建一个自定义组件,如下所示: const EventsTab = ({...props, record}
我是一名优秀的程序员,十分优秀!