【发布时间】:2021-10-29 16:10:47
【问题描述】:
我有这样的 Antd 的 Cascader:
当我点击编辑按钮时,它会打开如下模式。
const showModal = (record) => {
console.log('record', record); // this is current record which has existing value to be displayed in cascader
form.setFieldsValue(record);
setVisible(true);
};
如何将初始值或现有值提供给 Cascader?
<Cascader
defaultValue={['zhejiang', 'hangzhou', 'xihu']}
options={propertyOptions}
loadData={loadCompanies}
onChange={onChange}
changeOnSelect
/>
使用 defaultValue 之类的道具似乎不起作用。
当我加载 propertyOptions 时,它会加载类似的值
property1,
property2
当我点击 property1 时,它会动态加载子项。
所以选择的值是例如财产1>公司1
但是当我单击编辑模式时,它只有父值。 (当我在父母点击时加载他们时,孩子们不会在那里)。
当我点击 modal 时,它有整个项目数据,所以也许我可以用它来显示硬编码值或其他东西?
更新:
这就是我填写 propertyOptions 的方式
function setPropertiesAsOptions(propertiesQuerySnapshot) {
propertiesQuerySnapshot.forEach((doc) => {
options.push({
value: doc.id,
label: doc.data().propertyName,
isLeaf: false,
});
});
setPropertyOptions(options);
}
【问题讨论】:
-
您能展示一下您的正确 1 和属性 2 的样子吗?还有什么是编辑模式?编辑模态时是新模态还是关于情况?)
-
我更新了问题。也编辑模式意味着它的编辑数据。因此应在此级联中预先填充现有的选定值
标签: reactjs antd ant-design-pro