。。。。。。

来源:3-4 期刊内容列表查询

qq_慕侠0125797

2020-09-24 16:46

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

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

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

写回答 关注

6回答

  • 沁尘
    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)



    qq_慕侠0...

    已解决,谢谢老师

    2020-09-25 16:04:25

    共 3 条回复 >

  • 沁尘
    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

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

    沁尘

    你贴一下具体代码

    2020-09-24 20:37:43

    共 1 条回复 >

0到1快速构建自己的后台管理系统

开源框架LIN-CMS+NodeJS+Vue 快速构建UI好看+功能便捷的后台管理系统

21766 学习 · 145 问题

查看课程