首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >验证表自定义排序"TypeError:无法读取未定义的属性'filter‘“

验证表自定义排序"TypeError:无法读取未定义的属性'filter‘“
EN

Stack Overflow用户
提问于 2020-09-10 17:12:06
回答 1查看 374关注 0票数 1

我在vuetify中有一个自定义排序实现的问题。

代码语言:javascript
复制
      <v-data-table
        :headers="table.headers"
        :items="table.items"
        :search="search"
        disable-pagination
        :header-props="{sortByText: 'sortiere nach...'}"
        :loading="loading"
        hide-default-footer
        :custom-sort="customSort"
        @click:row="rowClickHandler"
      />

这是我现在使用的customSort函数

代码语言:javascript
复制
    customSort(items, sortBy, sortDesc, locale) {
      if (!this.table.loading) {
        console.log(items)
        console.log(sortBy)
        console.log(sortDesc)
        console.log(locale)
      }
    }

问题是,我得到了一个很大很胖的Error in render: "TypeError: Cannot read property 'filter' of undefined",也许这取决于我使用axios获取异步数据?

我在我的created()块中像这样获取

代码语言:javascript
复制
    async fetchUsers() {
      await axios
        .get('myApiPath')
        .then((res) => {
          this.table.items = res.data
          this.table.loading = false
        })
        .catch((err) => {
          console.log(err)
        })
    },
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-10 17:55:38

您需要从customSort()返回一个数组。我相信这和你的异步数据获取没有任何关系。

代码语言:javascript
复制
customSort(items, sortBy, sortDesc, locale) {
  if (!this.table.loading) {
    console.log(items.map(e => e.calories));
    console.log(sortBy);
    console.log(sortDesc);
    console.log(locale);
  }

  // sort items here

  return items;
}

这是一个custom-sort()sample implementation

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63826482

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档