在vue中對數(shù)組對象中的某一屬性按照字母排序

data(){
return {
options:[
      { value: "13423", label: "dfsdfdsf" },
        { value: "34232", label: "fdsfdsfsd" },
        { value: "34323", label: "afdsfds" },
        { value: "2433", label: "bgdfdg" },
        { value: "5343", label: "badvfsfs" },
        { value: "32346", label: "bbdfsdfsd" },
        { value: "42347", label: "cdfdsfs" },
        { value: "75658", label: "gdfddg" },
        { value: "14344", label: "dfgfdgfd" },
        { value: "14450", label: "vdfsdfds" },
]
}

created(): {
this.options = this.options.sort(this.sortBankList("label"));
}
},

methods:{
  sortBankList(propertyName) {
      return function sortList(object1, object2) {
        const value1 = object1[propertyName];
        const value2 = object2[propertyName];
        if (value2 < value1) {
          return 1;
        }
        if (value2 > value1) {
          return -1;
        }
        return 0;
      };
    },
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容