2

VueJS 2 で項目のリストを slice().sort() で並べ替えようとしていますが、効果がありません。vuejs 1 には優れた orderBy フィルターがありましたが、これは削除されました。私の現在の設定は次のとおりです。

<table>
        <thead>
          <tr>
            <th v-for="column in columns" v-on:click="sortBy(column)">{{ column }}</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="customer in customerslist">
            <td>{{ customer.firstname }}</td>
            <td>{{ customer.surname }}</td>
            <td>{{ customer.added }}</td>
            <td></td>
          </tr>
        </tbody>
      </table>

...

      sortBy(sortKey) {
        this.customerslist = this.customerslist.slice().sort(sortKey);
        console.log(sortKey);
        console.log(this.customerslist[0].firstname);
      }

顧客との 2 次元配列です。各顧客には、名、姓、および追加フィールドがあります。

ただし、firstname 列ヘッダーをクリックすると、コンソールに常に同じ名が返されます (これはアルファベット順に正しいものではありません)。適切なドキュメントが見つからないため、並べ替えはどのように機能しますか。

4

1 に答える 1