mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 11:07:52 +08:00
Picker 初始值中没有选项的话,从 source 接口中拉取
This commit is contained in:
parent
f12b029825
commit
0c00d876d2
@ -4,7 +4,7 @@ import cx from 'classnames';
|
|||||||
import Button from '../../components/Button';
|
import Button from '../../components/Button';
|
||||||
import {SchemaNode, Schema, Action} from '../../types';
|
import {SchemaNode, Schema, Action} from '../../types';
|
||||||
import find = require('lodash/find');
|
import find = require('lodash/find');
|
||||||
import {anyChanged, autobind, getVariable, noop} from '../../utils/helper';
|
import {anyChanged, autobind, getVariable, noop, createObject} from '../../utils/helper';
|
||||||
import findIndex = require('lodash/findIndex');
|
import findIndex = require('lodash/findIndex');
|
||||||
import Html from '../../components/Html';
|
import Html from '../../components/Html';
|
||||||
import {filter} from '../../utils/tpl';
|
import {filter} from '../../utils/tpl';
|
||||||
@ -59,6 +59,10 @@ export default class PickerControl extends React.PureComponent<PickerProps, any>
|
|||||||
|
|
||||||
input: React.RefObject<HTMLInputElement> = React.createRef();
|
input: React.RefObject<HTMLInputElement> = React.createRef();
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.fetchOptions();
|
||||||
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps: PickerProps) {
|
componentWillReceiveProps(nextProps: PickerProps) {
|
||||||
const props = this.props;
|
const props = this.props;
|
||||||
|
|
||||||
@ -69,6 +73,38 @@ export default class PickerControl extends React.PureComponent<PickerProps, any>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps: PickerProps) {
|
||||||
|
const props = this.props;
|
||||||
|
|
||||||
|
if (props.value !== prevProps.value) {
|
||||||
|
this.fetchOptions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchOptions() {
|
||||||
|
const {value, formItem, valueField, labelField, source, data} = this.props;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!source ||
|
||||||
|
!formItem ||
|
||||||
|
!formItem.selectedOptions.length ||
|
||||||
|
formItem.selectedOptions[0][valueField || 'value'] !== formItem.selectedOptions[0][labelField || 'label']
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
formItem.loadOptions(
|
||||||
|
source,
|
||||||
|
createObject(data, {
|
||||||
|
value: value,
|
||||||
|
op: 'loadOptions'
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
autoAppend: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
buildSchema(props: PickerProps) {
|
buildSchema(props: PickerProps) {
|
||||||
return {
|
return {
|
||||||
...props.pickerSchema,
|
...props.pickerSchema,
|
||||||
|
Loading…
Reference in New Issue
Block a user