Select autoComplet 支持配置 sendOn

This commit is contained in:
liaoxuezhi 2019-12-03 20:02:01 +08:00
parent f72b7f9ffc
commit d497256005
1 changed files with 20 additions and 22 deletions

View File

@ -141,31 +141,29 @@ export default class SelectControl extends React.Component<SelectProps, any> {
options: combinedOptions options: combinedOptions
}); });
} }
const ctx = createObject(data, {
term: input,
value: input
});
if (!isEffectiveApi(autoComplete, ctx)) {
return;
}
setLoading(true); setLoading(true);
return ( return env
isEffectiveApi(autoComplete, data) && .fetcher(autoComplete, ctx)
env .then(ret => {
.fetcher( let options = (ret.data && (ret.data as any).options) || ret.data || [];
autoComplete, this.cache[input] = options;
createObject(data, { let combinedOptions = this.mergeOptions(options);
term: input, setOptions(combinedOptions);
value: input
})
)
.then(ret => {
let options =
(ret.data && (ret.data as any).options) || ret.data || [];
this.cache[input] = options;
let combinedOptions = this.mergeOptions(options);
setOptions(combinedOptions);
return Promise.resolve({ return Promise.resolve({
options: combinedOptions options: combinedOptions
}); });
}) })
.finally(() => setLoading(false)) .finally(() => setLoading(false));
);
} }
mergeOptions(options: Array<object>) { mergeOptions(options: Array<object>) {