router.get('/commodities/sortable', utils.logged, function (req, res) {
Commodity.find({force_top:true}).sort("-force_top position -at").exec(function(err, items) {
res.render('commodities/sortable', {items:items, current: req.user});
});
//Commodity.find({force_top:true},function(error,docs){
// if(error){
// console.log(error)
// }else{
// res.render('commodities/sortable', {items:docs, current: req.user});
// }
//});
// res.render('commodities/sortable'); });
//商品排序2
router.post('/commodities/sortable', utils.logged, function (req, res) {
var list = req.body.list;
var bulk = Commodity.collection.initializeUnorderedBulkOp({useLegacyOps: true});
_.each(list, function(item, i) {
bulk.find({_id: new ObjectID(item.id)}).update({$set: {position: parseInt(item.position)}});
}); bulk.execute(function (err, result) {
if(err) console.error(err);
res.json(result);
});
}); router.get('/commodities/:id', utils.logged, function (req, res) {
thenjs.parallel([
function(cb) {
Commodity.findById(req.params.id).populate("tags").deepPopulate(commodity_deep_items).exec(function (err, item) {
if (item) item.photos = _.sortBy(item.photos, 'position');
cb(err, item);
});
},
function(cb) {
Zan.find({commodity:req.params.id}).populate('user').exec(function(err, zans) { cb(err, zans); });
},
function(cb) {
Category.find({ancestry:null}).exec(function(err, items) { cb(err, items); });
},
function(cb) {
Comment.find({commodity:req.params.id}).populate('user').exec(function(err, comments) { cb(err, comments); });
}
]).then(function(cb, results) {
var taglist = {}; _.each(TagList, function(t) {
_.set(taglist, t.v, t.d);
}); res.render('commodities/edit', {item:results[0], zans:results[1], current: req.user, categories: results[2], comments:results[3], taglist: taglist, moment:utils.moment});
});
});

主要是第一行与第三十一的路由设置,此两处路由设置若是颠倒位置,就会报错,原因就是,第二处路由,

/commodities/:id

此处路由 :id  可以是任意字符串,包括第一行路由设置的 sortable 若是第三十一行的路由排在前面 当请求/commodities/sortable 时,会进入/commodities/:id 路由,进入后找不到就会产生错误;

此处不知道能不能加一个next()处理,若是错误 next()继续执行,因为回调函数中省掉了next参数

express中路由设置的坑-----1的更多相关文章

  1. nodejs+express中设置登录拦截器

    在nodejs+express中,采用nodejs后端路由控制用户登录后,为了加强前端的安全性控制,阻止用户通过在浏览器地址栏中输入地址访问后台接口,在app.js中需要加入拦截器进行拦截: /*** ...

  2. Express ( MiddleWare/中间件 路由 在 Express 中使用模板引擎 常用API

    A fast, un-opinionated, minimalist web framework for Node.js applications. In general, prefer simply ...

  3. MVC3.0,路由设置实现伪静态IIS中404错误

    C# code? 1 2 3 4 5  routes.MapRoute("NewQueryTest.asp",                 "NewQueryTest ...

  4. CI中的url相关函数以及路由设置和伪静态技术

    当使用CI框架进行开发时,我们的一些数据传递的URL不应该写死,可以使用如下方法:比如说我们需要表单提交一个数据: 1.在controller控制器中我们需要先创建一个加载helper和视图的方法: ...

  5. MVC中如何设置路由指定默认页

    MVC中怎么设置默认页,在webform中 只要右键设置起始页就可以,但MVC中却没有这个功能,其实MVC更简单 如下: Login是控制器,Index 是动作 在全局Global.asax中改动下即 ...

  6. ICBC中的路由设置

    才去的中国工商银行,用身份证叫了A0076的号,前边还有26个人,闲来无聊果断拿出手机收取wifi.有两个ssid为ICBC的路由,信道分别是1号和6号,还好不需要密码,不过一会就连接上了. 那我先上 ...

  7. node.js零基础详细教程(5):express 、 路由

    第五章 建议学习时间4小时  课程共10章 学习方式:详细阅读,并手动实现相关代码 学习目标:此教程将教会大家 安装Node.搭建服务器.express.mysql.mongodb.编写后台业务逻辑. ...

  8. 记一次SpringBoot 开发中所遇到的坑和解决方法

    记一次SpringBoot 开发中所遇到的坑和解决方法 mybatis返回Integer为0,自动转型出现空指针异常 当我们使用Integer去接受数据库中表的数据,如果返回的数据中为0,那么Inte ...

  9. Angular4中路由Router类的跳转navigate

    最近一直在学习angular4,它确实比以前有了很大的变化和改进,好多地方也不是那么容易就能理解,好在官方的文档和例子是中文,对英文不太好的还是有很大帮助去学习. 官方地址:https://angul ...

随机推荐

  1. python-凯撒密码

    凯撒密码 简介:凯撒密码(Caesar)是最早的代换密码,对称密码的一种 算法:将每个字母用字母表中它之后的第k(称作位移值)个字母替代 代码: #-*-coding:utf-8-*- __autho ...

  2. Python简明教程---学习笔记

    字符双引号括起,数字不括: 分隔符为逗号(,),不能为空格 变量定义时即赋值 采用utf-8编码:#-*-coding:utf-8-*-或者#coding:utf-8 字符串定义:单/双引号括起 %符 ...

  3. 新手讲树:证明任意二叉树度为零的节点n0,永远比度为2的节点n2多1个

    证明:   设度为1的节点个数为n1,因为二叉树的所有节点的度都小于等于2, 所以n=n0+n1+n2; 又因为二叉树中,除了根节点所有的节点都有一个进入节点的分支,假设B为所有的分支,那么n=B+1 ...

  4. Oracle EBS-SQL (PO-1):检查供货比例异常.sql

    select distinct msr.sourcing_rule_name                     名称 , msi.description                      ...

  5. N个数依次入栈,出栈顺序有多少种

    题目:N个数依次入栈,出栈顺序有多少种? 首先介绍一下卡特兰数:卡特兰数前几项为 : 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 2 ...

  6. oracle 和informix 的基础区别

    1:查看表空间 select b.file_name 物理文件名, b.tablespace_name 表空间, b.bytes/1024/1024 大小M, (b.bytes-sum(nvl(a.b ...

  7. 在esx上 docker的网络桥接

    docker:/root# docker run -itd --net=none --name zjtest8_haproxy 192.168.32.150:5000/zjzc_centos6.5_m ...

  8. Struts2 一、 视图转发跳转

    <struts> <constant name="struts.118n.encoding" value="UTF-8"></co ...

  9. hdu 5584 LCM Walk(数学推导公式,规律)

    Problem Description A frog has just learned some number theory, and can't wait to show his ability t ...

  10. Log4Net不生成日志文件

    可能没有初始化配置,在Global文件Application_Start添加 log4net.Config.XmlConfigurator.Configure(); 或者输出日志进行初始化,如(Log ...