accounts := []users.Account{}Admin.DB.Preload("CurrencyObj").Where("member_id = ?", record.(*users.Member).ID).Find(&accounts)sort.Slice(accounts, func(i int, j int) bool { return accounts[i].Balance > accounts[j].Balance})return accounts num := []int{5,3,1,8,4,2}slice.Sort(num, func(i int, j int) bool { return num[i] < num[j]}fmt.Printf("%v\n", num) // --> []int{1, 2, 3, 4, 5, 8}
原文地址:https://www.cnblogs.com/zhangym/p/9144039.html
时间: 2024-10-09 14:41:54