在sails.js 中覆盖CRUD 蓝图 [英] CRUD blueprint overriding in sails.js

查看:26
本文介绍了在sails.js 中覆盖CRUD 蓝图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据风帆中的这个已关闭问题:https://github.com/balderdashy/sails/issues/835

According to this closed issue in sails: https://github.com/balderdashy/sails/issues/835

CRUD 蓝图覆盖当然,这将在 v0.10 中推出"

CRUD Blueprint Overrides "absolutely, this is coming in v0.10"

我想修改我的sailsjs 服务中的蓝图以允许命名根(在余烬中使用).目前,我必须使用与蓝图中已有的大部分重复的操作来自定义我创建的每个控制器.

I'd like to modify the blueprints in my sailsjs service to allow named roots (consuming in ember). Currently I'm having to customize every controller I create with actions that are largely duplicates of what is already in the blueprints.

我怀疑我现在可以将这段代码移出我的控制器并移到蓝图覆盖区域,但我不清楚将代码放在哪里.

I suspect that I can move this code out of my controllers now and into a blueprints override area, but I'm not clear on where to put that code.

非常感谢任何示例,甚至只是指向 .10 存储库中相关代码的指针.

Any examples or even just a pointer to the relevant code in sails the .10 repo would be greatly appreciated.

推荐答案

更新

为了以下述方式覆盖 Sails 1.0 中的蓝图,您必须首先为您的项目安装自定义蓝图"插件(npm install Sails-hook-custom-blueprints).

要覆盖 Sails v0.10 中的蓝图,您需要创建一个 api/blueprints 文件夹并添加您的蓝图文件(例如 find.jscreate.js 等)内.您可以查看默认操作的代码 在 Sails 蓝图钩子中抢先一步.

To override blueprints in Sails v0.10, you create an api/blueprints folder and add your blueprint files (e.g. find.js, create.js, etc.) within. You can take a look at the code for the default actions in the Sails blueprints hook for a head start.

也支持添加自定义蓝图,但它们目前不会自动绑定到路由.如果你创建了一个 /blueprints/foo.js 文件,你可以在你的 /config/routes.js 文件中绑定一个路由到它(例如):

Adding custom blueprints is also supported, but they currently do not get bound to routes automatically. If you create a /blueprints/foo.js file, you can bind a route to it in your /config/routes.js file with (for example):

'GET /myRoute': {blueprint: 'foo'}

这篇关于在sails.js 中覆盖CRUD 蓝图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆