问答详情
源自:3-4 期刊内容列表查询

。。。。。。

http://img1.mukewang.com/5f6c5c8e0001e44809340606.jpg

http://img1.mukewang.com/5f6c5cae0001b91f13120296.jpg

老师代码不报错最后查询出来的是个空的数组是怎么回事

提问者:qq_慕侠0125797 2020-09-24 16:46

个回答

  • 沁尘
    2020-09-25 09:48:57

    ==============service=================

    static async getContentList(){

            const movieList = await MovieDao.getMovieList()

            const musicList = await MusicDao.getMusicList()

            const sentenceList = await SentenceDao.getSentenceList()

            // 打印一下这三个结果

            console.log(movieList)

            console.log(musicList)

            console.log(sentenceList)



  • 沁尘
    2020-09-24 16:59:06

    光这么看没办法判断哪里有问题。确认下数据库是否数据,跟着视频核对下代码。

  • 撸吉他弹代码
    2021-05-05 01:58:12

    我也是返回空数组呢

  • weixin_慕雪5045121
    2021-04-06 16:35:04

    返回空数组的问题解决了吗,我的也是

  • qq_慕侠0125797
    2020-09-24 21:20:53

    =================v1============

    contentApi.get('/',async ctx => {

        const contentList = await ContentService.getContentList()

        ctx.json(contentList)

    })

    ===========(dao) movie===

    static async getMovieList(){

            return await MovieModel.findAll()

        }

    ==========(dao) music=====

    static async getMusicList(){

            const res = await MusicModel.findAll()

            return res

        }

    ===========(dao) sentence=======

    static async getSentenceList(){

            const res = await SentenceModel.findAll()

            return res

        }

    ==============service=================

    static async getContentList(){

            const movieList = await MovieDao.getMovieList()

            const musicList = await MusicDao.getMusicList()

            const sentenceList = await SentenceDao.getSentenceList()


            let res= []

            res.push.apply(res,movieList)

            res.push.apply(res,musicList)

            res.push.apply(res,sentenceList)

            

            res.sort((a,b) => b.created_at.localeCompare(a.created_at))

            return res

        }


  • qq_慕侠0125797
    2020-09-24 18:34:51

    老师我又对着视频重新写了一次,还是那样查询出来一个   [ ]   ,终端的代码没有报错误,是不是数据库有啥问题