如何显示自动完成中从服务器接收到的数组
我正在尝试向用户展示一个数组,其中包括我从服务器中获得的名称。为了允许用户从列表中选择所需的项目。
如果我只是写一个数组,那么一切都可以。
let liste=
[
{ label: 'The Shawshank Redemption', year: 1994 },
{ label: 'The Godfather', year: 1972 }
]
<Autocomplete
disablePortal
id="combo-box-demo"
options={liste}
onChange={(event , newevent) => {
setBehoerdeName(newevent) }}
renderInput={(params) => <TextField {...params} />}
/>
但是,如果我从服务器中获取数据,则会给出一个错误 虽然我也有一个数组。
let allDates = async function getAllDate() {
let list = await axios.get("/myWay")
if (list.data.success) {
let finalList = list.data.json.map(({name1, ort, plz}) => ({name1, ort, plz}));
return finalList
} else {
return null
}
};
<Autocomplete
disablePortal
id="combo-box-demo"
options={allDates }
onChange={(event , newevent) => {
setBehoerdeName(newevent) }}
renderInput={(params) => <TextField {...params} label="Behörden" />}
/>
我会收到此错误
Uncaught TypeError: options.filter is not a function
,试图将数据写入函数并将其称为选项中,但结果是相同的。
I'm trying to show the user an array with the names that I get from the server. To allow the user to select the desired item from the list.
If I just write an array, then everything works.
let liste=
[
{ label: 'The Shawshank Redemption', year: 1994 },
{ label: 'The Godfather', year: 1972 }
]
<Autocomplete
disablePortal
id="combo-box-demo"
options={liste}
onChange={(event , newevent) => {
setBehoerdeName(newevent) }}
renderInput={(params) => <TextField {...params} />}
/>
but if I get data from the server, it gives an error
although I get an array too.
let allDates = async function getAllDate() {
let list = await axios.get("/myWay")
if (list.data.success) {
let finalList = list.data.json.map(({name1, ort, plz}) => ({name1, ort, plz}));
return finalList
} else {
return null
}
};
<Autocomplete
disablePortal
id="combo-box-demo"
options={allDates }
onChange={(event , newevent) => {
setBehoerdeName(newevent) }}
renderInput={(params) => <TextField {...params} label="Behörden" />}
/>
i get this error
Uncaught TypeError: options.filter is not a function
I tried to write data to a function and call it in options but the result is the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论