sails.js 将ES2015生成器与co.js结合使用
示例
'use strict';
const co = require('co');
module.exports = {
//这是索引操作,路由通过/config/routes.js映射
index(req, res) {
co(function* index() {
//返回没有视图模型数据的视图
// This typically will return the view defined at /views/home/index.<view engine extension>
return res.view();
}).catch(res.negotiate); //捕获所有抛出的错误,并将错误传递给“协商”策略。
},
foo(req, res) {
co(function* foo() {
//从数据库中获取`FooBar`项目的数组
const items = yield FooBar.find();
//使用包含“FooBar”项数组的视图模型返回“foo”视图
return res.view({
items,
});
}).catch(res.negotiate); //捕获所有抛出的错误,并将错误传递给“协商”策略。
},
};
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短