From 998b86f8e31af56b3c15c6f425e6b3b26f262263 Mon Sep 17 00:00:00 2001 From: asd <374367073@qq.com> Date: Fri, 6 Dec 2019 08:59:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=87=E7=AB=A0=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/article.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/controllers/article.js b/controllers/article.js index 30fa713..5a4c4bc 100644 --- a/controllers/article.js +++ b/controllers/article.js @@ -2,14 +2,40 @@ // 获取文章列表 var articlefind = async (ctx, next) => { let articlelist; - await dbs.find("articlelists").then((res) => { + let tags=[] + await dbs.find("articlelists").then(async (res) => { + let num=0 articlelist = res.data + await dbs.find("articletag").then((res)=>{ + for(let i in articlelist){ + + for(let m in res.data){ + // console.log(res.data[m].articleid,articlelist[i].num_key,res.data[m].tagid) + if(res.data[m].articleid==articlelist[i].num_key){ + console.log(res.data[m].articleid,articlelist[i].num_key,res.data[m].tagid) + // console.log(res.data[m].articleid) + // console.log(res.data[m].articleid,res.data[m].tagid) + // tags.push([res.data[m].articleid]) + tags.push(res.data[m].tagid) + articlelist[i].tag=tags + + }else{ + tags=[] + } + } + + console.log(tags) + + + } + }) + ctx.body=articlelist }) next() } // 添加文章 -// 参数: title 文章标题, content 文章内容 tag 选择的标签id 形式: 1,2 +// 参数: title 文章标题, content 文章内容 tags 选择的标签id 形式: 1,2 var articleadd = async (ctx, next) => { let articleid=0 let month=parseInt(new Date(Date.now()).getMonth())+1 From ea74c739f68696a74107bfbadc70d39e6ac1db44 Mon Sep 17 00:00:00 2001 From: asd <374367073@qq.com> Date: Fri, 6 Dec 2019 09:10:12 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=87=E7=AB=A0=E6=A0=87=E7=AD=BE111?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/article.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/controllers/article.js b/controllers/article.js index 5a4c4bc..9b6b235 100644 --- a/controllers/article.js +++ b/controllers/article.js @@ -6,13 +6,14 @@ var articlefind = async (ctx, next) => { await dbs.find("articlelists").then(async (res) => { let num=0 articlelist = res.data - await dbs.find("articletag").then((res)=>{ + await dbs.find("articletag").then( async (res)=>{ + for(let i in articlelist){ for(let m in res.data){ // console.log(res.data[m].articleid,articlelist[i].num_key,res.data[m].tagid) if(res.data[m].articleid==articlelist[i].num_key){ - console.log(res.data[m].articleid,articlelist[i].num_key,res.data[m].tagid) + // console.log(res.data[m].articleid,articlelist[i].num_key,res.data[m].tagid) // console.log(res.data[m].articleid) // console.log(res.data[m].articleid,res.data[m].tagid) // tags.push([res.data[m].articleid]) @@ -24,10 +25,22 @@ var articlefind = async (ctx, next) => { } } - console.log(tags) + // console.log(tags) } + await dbs.find("label").then((res)=>{ + for(let i in articlelist){ + for(let m in articlelist[i].tag){ + console.log(articlelist[i].tag[m]) + for(let n in res.data){ + if(res.data[n].num_key==articlelist[i].tag[m]){ + articlelist[i].tag[m]=res.data[n].lablename + } + } + } + } + }) }) ctx.body=articlelist