不在 field 中也可以自己查找变量

This commit is contained in:
liaoxuezhi 2019-07-13 22:50:25 +08:00
parent 43c2134212
commit b43a151acc

View File

@ -5,6 +5,7 @@ import {Api, SchemaNode, PlainObject} from '../types';
import {filter} from '../utils/tpl';
import cx from 'classnames';
import Switch from '../components/Switch';
import { resolveVariable } from '../utils/tpl-builtin';
export interface SwitchProps extends RendererProps {
className?: string;
@ -47,18 +48,24 @@ export class SwitchField extends React.Component<SwitchProps, object> {
const {
className,
classPrefix: ns,
value,
placeholder,
trueValue,
falseValue,
onQuickChange,
option,
disabled,
name,
data
} = this.props;
let value = this.props.value;
let viewValue: React.ReactNode = <span className="text-muted">{placeholder}</span>;
let showOption = false;
if (value === void 0 && name) {
value = resolveVariable(name, data);
}
if (value == trueValue || value == falseValue) {
showOption = !!option;
viewValue = (