Open eightHundreds opened 1 year ago
还有recommend
这个我自问自答
/**
* for MixedSetter to check this setter if available
*/
condition?: (field: any) => boolean;
/**
* for MixedSetter to manual change to this setter
*/
initialValue?: any | ((field: any) => any);
顺便分享一个跟condtion相关, 看起来像bug的case
{
title: {
label: 'children',
tip: '子节点',
},
name: 'children',
description: '子节点',
setter: {
componentName: 'MixedSetter',
props: {
setters: [
'SlotSetter',
'StringSetter',
'VariableSetter',
],
},
},
},
默认情况优先展示SlotSetter, 其表现是一个开关(switch),然后把它关闭后会自动切换成StringSetter
是因为关闭后, SlotSetter会把这个属性值变成null, 然后他就不能满足SlotSetter默认的condtion判断, 所以MixedSetter选择了第二个StringSetter
解决办法是
{
title: {
label: 'children',
tip: '子节点',
},
name: 'children',
description: '子节点',
setter: {
componentName: 'MixedSetter',
props: {
setters: [
{
componentName: 'SlotSetter',
+ condition: () => true,
},
'StringSetter',
'VariableSetter',
],
},
},
},
这个condition函数的作用是什么? 它只用在MixedSetter吗?