fix: 修复多对多筛选中间表无效 (#962)
Reviewed-on: daoyoucloud/tachybase#962 Reviewed-by: sealday <zhanglin@daoyoucloud.com> Co-authored-by: wjh <wwwjh0710@163.com> Co-committed-by: wjh <wwwjh0710@163.com>
This commit is contained in:
parent
2b0e1fa573
commit
3723ad1486
@ -303,6 +303,7 @@ export const ThroughCollection = observer(
|
|||||||
const record = useRecord();
|
const record = useRecord();
|
||||||
const value = record[field.props.name];
|
const value = record[field.props.name];
|
||||||
const [initialValue, setInitialValue] = useState(value || field.initialValue);
|
const [initialValue, setInitialValue] = useState(value || field.initialValue);
|
||||||
|
const [defOptions, setDefOptions] = useState([]);
|
||||||
|
|
||||||
const loadCollections = () => {
|
const loadCollections = () => {
|
||||||
const filteredItems = getCollections().filter((item) => {
|
const filteredItems = getCollections().filter((item) => {
|
||||||
@ -320,6 +321,7 @@ export const ThroughCollection = observer(
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const data = loadCollections();
|
const data = loadCollections();
|
||||||
setOptions(data);
|
setOptions(data);
|
||||||
|
setDefOptions(data);
|
||||||
if (value) {
|
if (value) {
|
||||||
const option = data.find((v) => v.value === value);
|
const option = data.find((v) => v.value === value);
|
||||||
setInitialValue(option?.label || value);
|
setInitialValue(option?.label || value);
|
||||||
@ -327,13 +329,13 @@ export const ThroughCollection = observer(
|
|||||||
}, []);
|
}, []);
|
||||||
const handleSearch = (value: string) => {
|
const handleSearch = (value: string) => {
|
||||||
if (value) {
|
if (value) {
|
||||||
const filteredOptions = options.filter((option) => {
|
const filteredOptions = defOptions.filter((option) => {
|
||||||
return option.label.toLowerCase().includes(value.toLowerCase());
|
return option.label.toLowerCase().includes(value.toLowerCase());
|
||||||
});
|
});
|
||||||
|
|
||||||
setOptions(filteredOptions);
|
setOptions(filteredOptions);
|
||||||
} else {
|
} else {
|
||||||
const data = loadCollections();
|
setOptions(defOptions);
|
||||||
setOptions(data);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user