将多个路由添加到单个路由后,值未正确路由

时间:2019-06-13 07:44:14

标签: node.js mongoose ejs

我正在尝试结节猫鼬。当我开始将多个路由添加到单个路由时,我陷入了困境。当我第一次将add函数添加到仅一页时,它的运行情况非常好。但是,当开始向同一路由器添加添加功能时,它现在无法正常工作。谁能帮忙吗?

route.js

//category

router.get('/category',async (req,res,next) => {
  const categoryPages = await Category . find();
  res.render('category' , {
      categoryPages
  });

});

router.post('/addCategory', async (req,res,next) => { 
  const categoryPages = new Category({
      category : req.body.category ,
      status : req.body.status
  });
  await categoryPages.save();
  console.log('received');
  res.redirect('/category');
});

//story

router.get('/Story',async (req,res) => {try {
  var Stories = await Story.find();
  res.render('Story' , {
      Stories
  });
} catch(e) {
  console.log(e);
}

});


router.post('/addStory', async (req,res) => {try{
  var successStories = new Story({
      Story : req.body.Story ,
      StoryStatus : req.body.StoryStatus
  });
  await Stories.save();
  console.log('received');
  res.redirect('/Story');
} catch(e) {
  console.log(e);
}

});


//patners
router.get('/partners',async (req,res) => {try {
  const partners = await Partners.find();
  res.render('partners' , {
      partners
  });
} catch(e) {
  console.log(e);
}

});


router.post('/addpartners', async (req,res) => {try{
  const partners = new Partners({
      partnersList : req.body.partnersList ,
      partnerStatus : req.body.partnerStatus
  });
  await partners.save();
  console.log('received');
  res.redirect('/partners');
} catch(e) {
  console.log(e);
}

});

model.js

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const CategorySchema = new Schema({
    category: {
        type:String
    },
    status: {
        type:String
    }

})
const SuccessStorySchema = new Schema({
    Story: {
        type:String
    },
    StoryStatus: {
        type:String
    }
})


const PartnerSchema = new Schema({
    partnersList: {
        type:String
    },
    partnerStatus: {
        type:String
    }
})


module.exports =  mongoose.model('Category', CategorySchema);
module.exports =  mongoose.model('SuccessStory',SuccessStorySchema);
module.exports =  mongoose.model('Partners',PartnerSchema);

Story.ejs

<% for(var i = 0; i < successStories. length; i++) { %>     
<tr>
    <td><%= i+1 %></td>
    <td><%= successStories[i].Story %></td>
    <td><%= successStories[i].StoryStatus %></td>
</tr>
<%  } %>

Partners.ejs

<% for(var i = 0; i < partners. length; i++) { %>           
   <tr>
     <td><%= i+1 %></td>
     <td><%= partners[i].partnersList %></td>
     <td><%= partners[i].partnerStatus %></td>
   </tr>
<%  } %>  

Category.ejs

<% for(var i = 0; i <categoryPages. length; i++) { %>   
<tr>
 <td><%= i+1 %></td>
 <td><%= categoryPages[i].category %></td>
 <td><%= categoryPages[i].status %></td>
</tr>
<%  } %>  

获得结果 enter image description here

我在cmd中得到

enter image description here

在猫鼬中,未添加任何记录,也未显示任何模式

0 个答案:

没有答案