Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

如何让route.get获取到当前url的参数id值?

$
0
0

我的代码如下,请问可以在route里直接获取url的id值吗? 如果不行,应该怎么做 求助!!!!! html中:

  • <a href="#/admin/sharepass/<%=share.id%>">审核
    

js中:

  • 	     var adminsharepass = {
    
  • 			  url:"/admin/sharepass/:id",
    
  • 			class:"adminsharepass",
    
  • 			render: function (){
    
  • 				 return $._ajax({
    
  • 				  url:"/admin/sharepass/:id",
    
  • 				  type:"get"
    
  • 				 });
    
  • 		}
    

route中:

  • 	router.get('/sharepass/:id', function(req, res, next) {
    
  • 		let sql = "select*from share WHERE id=?";
    
  • 	   util.getConn().queryAsync(sql,[req.param('id')]).then((result)=>{
    
  • 		 res.render("admin/adminsharepass.html",{share:result});
    
  • 	  }).catch((err)=>{
    
  • 	  res.send("error");
    
  • 	  })
    
  • 	});

Viewing all articles
Browse latest Browse all 14821

Trending Articles