diff --git a/controllers/grouping.js b/controllers/grouping.js index 023a233..28019b4 100644 --- a/controllers/grouping.js +++ b/controllers/grouping.js @@ -1,6 +1,6 @@ //添加分组 var groupadd = async (ctx, next) => { - await dbs.add("group", { groupname: ctx.query.groupname, fuid: ctx.query.fuid }) + await dbs.add("group", { groupname: ctx.query.groupname, fuid: ctx.query.fuid == null ? '0' : ctx.query.fuid }) ctx.body = "添加成功" } // 删除分组 @@ -10,7 +10,6 @@ var groupdel = async (ctx, next) => { } // 获取分组 var groupfind = async (ctx, next) => { - let group = [] await dbs.find("group").then((res) => { let tree = function (data) { let map = {}; @@ -28,15 +27,16 @@ var groupfind = async (ctx, next) => { } else { val.push(it); } + console.log(parent) }) return val; } + if(res.data.length == 0 ){ + ctx.body="{code:0,data:[]}" + }else{ + ctx.body = JSON.stringify(tree(res.data)) - console.log(tree(res.data)) - - - // console.log(JSON.stringify(group)) - ctx.body = JSON.stringify(tree(data)) + } next() }) }