收藏
回答

sort函数在小程序端,和云开发的云函数数据不一致问题?

function findTop(members{
    /*
    sort 在客户端小程序云端,排序数据不一致
   
    */
    let top = {
        realName'',
        openid'',
        price0
    }
    if (members.length > 0) {
        top = members[0]
        for (let i = 0; i < members.length; i++) {
            if (top.price < members[i].price) {
                top = members[i]
            }
        }
    }
    return top
}

function  findTop2(members){
 let top = {
        realName'',
        openid'',
        price0
    }
   
    if (members.length > 0) {
        members.sort(function (a, b{
            return b.price - a.price
        })
        console.log(members)
        top = members[0]
    }


    return top
}
let  members=[{ "avatarUrl""""nickName""""price"120"realName""黄玉如""createDate""2020-12-28  14:52:13""openid""oalIN5BbjgUnIIJDGVycjxiY3MKE" }, { "avatarUrl""""nickName""""price"90"realName""王铮""createDate""2020-12-28  14:57:37""openid""oalIN5Jy9qMHK-sEVmXc8sfmN5-0" }, { "avatarUrl""""nickName""""price"150"realName""郑兴响""createDate""2020-12-28  14:58:11""openid""oalIN5POkZXM6g-aWp4NhZVsXMaM" }, { "avatarUrl""https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTINV6SGu6wxibeCjiafk3eIX55BDq8JNibmQtUpVcMtMqKb9aAJBlJ1qGfWibXWg9PTib3JKJgQgghkswQ/132""nickName""倚歌""price"100"realName""郑锦平""createDate""2020-12-28  15:24:54""openid""oalIN5CAm9mGDWgPkqbqqkNLiSuY" }, { "avatarUrl""https://thirdwx.qlogo.cn/mmopen/vi_32/PbRsCBUfCWbcBYorXZJunpBSBtXNHPVfk65A4lyXzEJuVqNibib1P0033CBmkdC7viboVt7EgqdQDK8qicD7PPQfibg/132""nickName""林英枝""price"100"realName""林英枝""createDate""2020-12-28  15:26:33""openid""oalIN5LIatxlx75Q2kz6Ge5UTnvs" }, { "avatarUrl""""nickName""""price"160"realName""唐晓秋""createDate""2020-12-28  15:38:26""openid""oalIN5K1rd-Vs3rYHZk5sxaexu0g" }, { "avatarUrl""""nickName""""price"120"realName""蔡尚芳""createDate""2020-12-28  15:41:32""openid""oalIN5LNykPxzyUv5T0Jr0K2u7Y0" }, { "avatarUrl""""nickName""""price"120"realName""黄文娟""createDate""2020-12-28  15:58:13""openid""oalIN5BkNvpJEDqszA0OhmnFr6Yc" }, { "avatarUrl""""nickName""""price"156"realName""郑升""createDate""2020-12-28  16:42:13""openid""oalIN5HRmVk_QvAixiPJhbi-noj4" }, { "avatarUrl""""nickName""""price"98"realName""王晓霞""createDate""2020-12-28  16:50:32""openid""oalIN5LusQTo8Z-B5nnhmL5slP2w" }, { "avatarUrl""https://thirdwx.qlogo.cn/mmopen/vi_32/F5QaS9RCtlywN2gY9ZtJLcNeuzbZLM50s8jaqVfa3XN0gc0059iccuwODWqica90PicKsnfIFibU8G4OX6hibMhPnKA/132""nickName""林乐平""price"120"realName""林乐平""createDate""2020-12-28  16:51:42""openid""oalIN5BQ7b_FUj9basCugBBqHfpA" }, { "avatarUrl""""nickName""""price"120"realName""叶雪琴""createDate""2020-12-28  17:06:08""openid""oalIN5P_MRv8YWlyU3yr_EQEb8Tw" }, { "avatarUrl""https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLcf7o6fEe1g3Hy21PpYyKF3u1KsKTOaC3Yd6tibNhopicNMOxVmQ5Mw7cMP5AM1icyIYwvyiaVVBibVyQ/132""nickName""王小二""price"120"realName""王小喆""createDate""2020-12-28  17:08:49""openid""oalIN5PGcUPWLRpFhfglMiZnhvh4" }, { "avatarUrl""""nickName""""price"120"realName""龚美兰""createDate""2020-12-28  17:10:18""openid""oalIN5IppKUaUDhXZDyCTmlwEtEM" }, { "avatarUrl""""nickName""""price"160"realName""张巧玲""createDate""2020-12-28  17:22:44""openid""oalIN5NQPAuQFUirAkOfIC1zkSds" }]
// findTop2  云开发端返回:  唐晓秋
//findTop   小程序端:   张巧玲
//z这两者都是160的price
//q求解
回答关注问题邀请回答
收藏

2 个回答

  • 陈宇明
    陈宇明
    2020-12-31

    建议统一都用云函数的

    2020-12-31
    有用
    回复
  • 铅笔画不出蜡笔的味道
    铅笔画不出蜡笔的味道
    2020-12-28

    写法不一样,返回值不一样正常

    2020-12-28
    有用
    回复 4
    • C.ROBBER🥤
      C.ROBBER🥤
      2020-12-29
      在小程序端测试都是topd都是,唐。云开发的返回时,张
      2020-12-29
      回复
    • C.ROBBER🥤
      C.ROBBER🥤
      2020-12-29
      小程序端,两种top都是唐。
      2020-12-29
      回复
    • 铅笔画不出蜡笔的味道
      铅笔画不出蜡笔的味道
      2020-12-29回复C.ROBBER🥤
      members在小程序和云开发中的排序不一样,先读到的返回了
      2020-12-29
      回复
    • 铅笔画不出蜡笔的味道
      铅笔画不出蜡笔的味道
      2020-12-29回复C.ROBBER🥤
      2020-12-29
      1
      回复
登录 后发表内容
问题标签