在地图功能中调用API
我是我想在地图功能中调用API的应用程序的新手,我认为我必须在该应用程序中调用API。
首先,我调用一个API,该API返回以这样的kendo表单渲染的元素列表:
import { Form, Field, FormElement } from "@progress/kendo-react-form";
...
const [tempAtr, setTempAtr] = useState([]);
...
const resAtr = await services.getTemplateSessionAtributi(sesijaV);
setTempAtr(resAtr.data.rlista); //tempAtr is filled with a list of elements (attributes)
...
{tempAtr.map((data) =>
<Field
required={data.required=== 1 ? true : false}
disabled={data.read_only === 1 ? true : false}
name={data.name}
component={
data.tpodatka_id === 1 ?Input:
data.tpodatka_id === 2 ?Input:
data.tpodatka_id === 3 ?DatePicker:
data.tpodatka_id === 4 ?DropDownList:
data.tpodatka_id === 5 ?TextArea :
data.tpodatka_id === 6 ?DropDownList:
data.tpodatka_id === 7 ?DropDownList:
data.tpodatka_id === 8 ?MultiSelect:
data.tpodatka_id === 9 ?MultiSelect:
Input}
label={data.name}
data={
data.tpodatka_id === (4 || 6 || 7 || 8 || 9) ?
**call an API and fetch data to fill the dropdown for that specific attribute id ** :
null
}
textField={data.tpodatka_id === (4 || 6 || 7 || 8 || 9) ? "name" : null}
dataItemKey={data.tpodatka_id === (4 || 6 || 7 || 8 || 9) ? "id" : null}
/>)}
因此,在数据部分中,我必须将attribut_id的API称为一个参数知道该怎么做?可以有一个下拉属性的1或5或15,因此,我唯一能想到的就是调用映射功能中的API并在返回时分配值。
帮助任何人?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最佳选择是提取
下拉
单独的React组件&amp;在其使用
中进行API调用。您可以将id
作为道具传递。示例()Best option is to extract the
dropdown
a separate react component & make the API call in it'suseEffect
. You can pass theid
as a prop. Example (Codesandbox)