如何显示自动完成中从服务器接收到的数组

发布于 2025-02-03 03:26:33 字数 1513 浏览 3 评论 0原文

我正在尝试向用户展示一个数组,其中包括我从服务器中获得的名称。为了允许用户从列表中选择所需的项目。

如果我只是写一个数组,那么一切都可以。

   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} />}
  />

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文