【问题标题】:Custom sort in <v-data-table> stays in a loop<v-data-table> 中的自定义排序保持循环
【发布时间】:2020-09-18 18:36:19
【问题描述】:

我有一张桌子,我做了一个custom-sort,但由于某种原因,该方法停留在一个循环中。

<v-card>
      <v-toolbar flat>
        <v-toolbar-title>{{ $t('locations.list.title') }}</v-toolbar-title>
        <v-divider class="mx-4" inset vertical></v-divider>
        <div>
          <v-text-field
            append-icon="fa fa-search"
            v-model="params.query"
            :label="$t('locations.labels.search')"
            :disabled="isLoading"
            single-line
            hide-details
            v-debounce:1500="search"
          ></v-text-field>
        </div>
        <v-spacer></v-spacer>
        <v-btn color="primary" :to="{ name: 'locations:create' }">
          {{ $t('locations.labels.add') }}
          <v-icon right>fa fa-plus</v-icon>
        </v-btn>
      </v-toolbar>
      <v-data-table
        :headers="headers"
        :items="locations"
        :page.sync="pagination.current_page"
        :items-per-page="pagination.per_page"
        :loading="isLoading"
        hide-default-footer
        :multi-sort="true"
        :custom-sort="customSort"
        @page-count="pageCount = $event"
      >
        <template v-slot:item.actions="{ item }">
          <v-btn icon :to="{ name: 'locations:edit', params: { id: item.id } }">
            <v-icon>fa fa-edit</v-icon>
          </v-btn>
          <v-btn icon @click="requestDeleteConfirmation(item)">
            <v-icon>fa fa-trash</v-icon>
          </v-btn>
        </template>
      </v-data-table>
      <v-pagination
        v-model="pagination.current_page"
        :length="pagination.last_page"
        @input="search"
      ></v-pagination>
    </v-card>

这是我的排序方法:

customSort(items, index, isDesc) {
    if (index[0]) {
        const $sort = index
            .reduce((carry, item, index) => {
                const name = item;
                const order = isDesc[index] ? 'ASC' : 'DESC';
                const sort = `${name}:${order}`;
                carry.push(sort);
                return carry;
            }, [])
            .join(',');
        this.params = { ...this.params, $sort };
        console.log('[carry]', $sort);
        this.search();
    } else {
        this.$delete(this.params, '$sort');
    }
    return items;
},

【问题讨论】:

    标签: javascript vue.js vuejs2 vuetify.js


    【解决方案1】:

    我怀疑customSort() 触发search()search() 触发customSort() 存在循环问题。

    如果不是,我的下一个猜测是它与v-data-table 有关。您能给我们提供有关该组件的更多信息吗?是来自图书馆还是你自己写的?

    【讨论】:

    • 19/5000 我定义了该方法,因为我必须将过滤器信息发送到我在 API 中拥有的方法,但我不知道为什么该方法停留在我尝试删除的无限循环中搜索()
    猜你喜欢
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    • 2021-02-17
    • 2013-12-16
    • 1970-01-01
    相关资源
    最近更新 更多