mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
Merge pull request #5756 from sqzhou/combo-additem
feat:combo组件添加addItem动作
This commit is contained in:
commit
2272fa46d2
@ -921,6 +921,7 @@ combo 还有一个作用是增加层级,比如返回的数据是一个深层
|
||||
|
||||
| 动作名称 | 动作配置 | 说明 |
|
||||
| -------- | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
|
||||
| addItem | `item: object` 新增项的值 | 只有开启`multiple`模式才能使用, `multiple`模式下,给新增项添加默认值 |
|
||||
| clear | - | 清空 |
|
||||
| reset | - | 将值重置为`resetValue`,若没有配置`resetValue`,则清空 |
|
||||
| setValue | `value: object \| Array<object>` 更新的值<br/>`index?: number` 指定更新的数据索引, 1.10.1 及以上版本引入 | 更新数据,对象数组针对开启`multiple`模式, `multiple`模式下可以通过指定`index`来更新指定索引的数据 |
|
||||
|
@ -447,13 +447,48 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||
const actionType = action?.actionType as string;
|
||||
const {onChange, resetValue} = this.props;
|
||||
|
||||
if (actionType === 'clear') {
|
||||
if (actionType === 'addItem') {
|
||||
this.addItemValue(args?.item ?? {});
|
||||
}
|
||||
else if (actionType === 'clear') {
|
||||
onChange('');
|
||||
} else if (actionType === 'reset') {
|
||||
onChange(resetValue ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
addItemValue(itemValue: any) {
|
||||
const {
|
||||
flat,
|
||||
joinValues,
|
||||
addattop,
|
||||
delimiter,
|
||||
disabled,
|
||||
submitOnChange
|
||||
} = this.props;
|
||||
|
||||
if (disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
let value = this.getValueAsArray();
|
||||
|
||||
this.keys.push(guid());
|
||||
|
||||
if (addattop === true) {
|
||||
value.unshift(itemValue);
|
||||
}
|
||||
else {
|
||||
value.push(itemValue);
|
||||
}
|
||||
|
||||
if (flat && joinValues) {
|
||||
value = value.join(delimiter || ',');
|
||||
}
|
||||
|
||||
this.props.onChange(value, submitOnChange, true);
|
||||
}
|
||||
|
||||
getValueAsArray(props = this.props) {
|
||||
const {flat, joinValues, delimiter, type} = props;
|
||||
let value = props.value;
|
||||
|
Loading…
Reference in New Issue
Block a user