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. mongo设计(三)

    原文:http://blog.mongodb.org/post/88473035333/6-rules-of-thumb-for-mongodb-schema-design-part-3 By Wil ...

  2. delphi 发送Windwos消息控制按钮(控制计算器里的某一个按钮)

    procedure TfrmMain.btnSendClick(Sender: TObject); var hCalc, h1: Cardinal; begin WinExec('calc', SW_ ...

  3. java--工具方法

    根据时间戳得到具体的时间: public static void main(String[] args) { SimpleDateFormat sdf = new SimpleDateFormat(& ...

  4. mysql排行榜sql的实现

    SELECT num_rows AS num_rows, openid , openid, money FROM lt_cash_user ) t ORDER BY money DESC ) t1 W ...

  5. .NET,你忘记了么?(八)—— 从dynamic到特性误用 [转]

    1. 摘要 每个程序员都想写出漂亮的代码,但是什么是漂亮,这个我想每个人都有着自己的看法.那么我就说几种典型的想法: A. 写出别人看不懂的代码,让别人觉得很高深. B. 写出简短的代码 C. 用最新 ...

  6. AngularJS学习资源

    图灵社区 : 图书 : AngularJS入门教程 http://www.ituring.com.cn/book/1206 AngularJS 教程 | 菜鸟教程 http://www.runoob. ...

  7. MySqL触发器以及常用转换函数注意事项

    1,触发器(http://www.cnblogs.com/zzwlovegfj/archive/2012/07/04/2576989.html)       1.MYSQL中触发器中不能对本表进行 i ...

  8. FAQ:win7和win8 64位注册ocx控件方法

    win7/win8 问题所在: 64位的系统一般都是可以安装32位程序的, 执行         C:\Windows\SysWOW64\regsvr32.exe 而不是 C:\Windows\Sys ...

  9. Sublime Text3 插件安装教程

    链接地址:http://jingyan.baidu.com/article/4d58d541caeeaa9dd4e9c093.html

  10. Linux学习之traceroute命令

    通过traceroute我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径.当然每次数据包由某一同样的出发点(source)到达某一同样的目的地(destination)走的路径可能会不一 ...