1 router.get ('/commodities/sortable ', utils.logged, function (req, res) {2 commodity.find ({force_top:true}). Sort ("-force_top position-at"). EXEC (function (err, items) {3 res.render (' commodities/sortable ', {items:items, current:req.user});4 });5 //commodity.find ({force_top:true},function (error,docs) {6 //if (error) {7 //Console.log (Error)8 //}else{9 //Res.render (' commodities/sortable ', {items:docs, current:req.user});Ten // } One //}); A //Res.render (' commodities/sortable '); - - }); the //Product sort 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)}}); + }); A at Bulk.execute (function (err, result) { - if (err) console.error (err); - Res.json (result); - }); - }); - in - to router.get ('/commodities/:id ', utils.logged, function (req, res) { + Thenjs.parallel ([ - function (CB) { the 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);Panax Notoginseng }); - }, the function (CB) { + zan.find ({commodity:req.params.id}). Populate (' user '). EXEC (function (err, Zans) {CB (err, Zans);}); A }, the 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) { the var taglist = {}; - Wuyi _.each (TagList, function (t) { the _.set (TagList, T.V, T.D); - }); Wu - res.render (' Commodities/edit ', {item:results[0], zans:results[1], Current:req.user, categories:results[2], com Ments:results[3], taglist:taglist, moment:utils.moment}); About }); $});
Mainly the first line and the 31st routing settings, the two routing settings if the reverse position, will be error, the reason is that the second route,
/commodities/:id
Routing here: The ID can be any string, including the first route set by the sortable if the 31st row of routes in front when the request/commodities/sortable, will enter the/commodities/:id route, If you cannot find it after entering, you will have an error;
I do not know if I can add a next () processing, if the error next () to continue execution, because the callback function omitted the next parameter
Express Middle set by pit-----1