Tag: sails.js

如何将数据传递到引导模型?

我的基本环境是node.js, sails.js和MongoDB。 我使用从数据库中提取的数据和坐标生成SVG,并使用“onclick”function调用打开模式窗口的函数。 我最终的目标是能够点击一个形状(代表一个长凳),并有一个模式打开与该形状/长椅的数据库信息。 我遇到的问题是如何将数据传递给模式,以便知道我select哪个形状/长凳,并列出该数据对象的数据。 目前,如果我通过select一个工作台打开一个模式,它会列出每个variables调用(this.example)为“未定义”,这显然是因为它没有传递该数据。 我如何生成形状/长凳的示例: // Foreach function generates shapes/benches from 'lab' collection in DB. // bFill variable is generated within this function based on whether this bench is set to active or not. <rect id="<%= lab.number%>" x="<%= lab.x %>" y="<%= lab.y %>" fill="<%= this.bFill %>" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" width="<%= lab.w %>" height="<%= […]

Node.js水线ORM – 生命周期callback – 在less数情况下,调用失败

我在我的应用程序中使用类似于这个模型,并且要求是在创buildlogging后,我想用新创build的loggingID更新所有者 。 所以我使用afterCreate方法来做同样的事情,但奇怪的行为是afterCreate方法不会在罕见的情况下被调用。 在手动创buildlogging时,我也有相同的行为,也是在摩卡单位testing中。 注意:这只在极less数情况下发生 。 那么,有没有最好的做法,或者我做错了什么? 我也有这个解决scheme以及..我所做的是,而不是使用afterCreate我在做同样的控制器行动..但只是期待知道为什么这会失败? **sample.js** module.exports = { schema: true, attributes: { name: { type: 'string', required: true }, owner : { model: 'sample' } }, afterCreate : function(values, next) { sample.update({id:values.id}, {owner: values.id}) .exec(function(err, result){ if(err){ next(err); } next(); }); } };

sails.js和多个参数

我一直在玩node.js和最近sails.js。 在node.js中,我使用了express,因此使用Routers.get很容易定义多个参数,但是我在帆中挣扎。 我已经使用内置命令创build了一个API,并注意到这将采用一个参数,默认为ID的名称,这是好的,如果我只是想使用一个参数,但我想调用一个函数,触发一个stored procedures需要4个参数。 这些都是通过Android设备调用的。 使用节点我发送类似的东西 myserveraddress/sendgrn/" + 1 + "/" + User + "/" + 1111 + "/" + 22) 这不是帆船工作,任何人都可以指出我的方向?

我在nodeMailer中的附件path不起作用(Sails应用程序)

我正在使用Sails框架构build一个Web应用程序。 我无法在电子邮件中添加图片。 这是我的邮件选项, var mailOptions = { from: 'mymail@gmail.com', to: to, subject: subject, html: html, attachments: [{ filename: "login-logo.png", filePath: "./assets/images/login-logo.png", cid: "logo-mail" }] }; 和我附上一个图像的我的ejs, <img src="cid:logo-mail" /> 在filePath我尝试 filePath:“./assets/images/login-logo.png” filePath:“/assets/images/login-logo.png” filePath:“/images/login-logo.png” filePath:“./images/login-logo.png” 但没有工作。 我不知道如何解决这个问题。 我真的需要一些帮助。 谢谢。

toJSON()不能在一个充满json对象的数组上工作

更新的问题 我使用sails.js v0.10.5 而我试图使用帆到JSON()和即时尝试删除一些东西从服务器之前,它被发送到客户端。 所以我有一个用户查找系统,有人可以写一个名字,然后Typeaead将查询我的数据库使用Sails作为后端。 现在,build议以包含多个用户的数组作为对象发送。 返回的对象如下 [ { "_id": "55394747d01d6777e09f4919", "index": 0, "guid": "1e08f17d-0163-40f6-b673-c9b1823b3e9b", "isActive": true, "balance": "$2,994.39", "picture": "http://placehold.it/32×32", "age": 28, "eyeColor": "brown", "name": "Grant Hughes", "gender": "male", "company": "CUBIX", "email": "granthughes@cubix.com", "phone": "+1 (972) 415-2367", "address": "656 Hornell Loop, Farmers, New York, 7735", "about": "Elit aute veniam commodo do dolore labore ullamco […]

用多对一的方式覆盖sails GET蓝图

警告:新的networking编程。 我有一个帆船项目中的以下内容: // in models/User.js // user has many videos module.exports = { attributes: { videos: { collection: 'video', via: 'owner' } } } // in models/Video.js // video has one user module.exports = { attributes: { owner: { model: 'user' } } } 我正在使用带有/ v1前缀的REST蓝图。 我试图重写GET / v1 / user /:id / video,或者自定义路由到GET / […]

使用http post()与sails沟通angular色

我在我的项目中使用angularjs和风帆js。 我得到问题与http get(),同时发送特殊字符从angular度到帆的数据。 我想用http post()而不是http get()。 任何人都可以帮忙吗? 我的代码看起来像 var employee = $scope.employee; $http({ method: 'POST', url: '/employee/saveEmployee', headers: {'Content-Type': 'application/json'}, data: {"empName":"employee .empName", "age":"employee .age", "designation":"employee .designation", "empType":"employee .empType" } }).success(function (data) { alert(data); });

使用Sails.js查询MySql表

我是Sails.js的新手。 我遵循了大部分文档,但无法从MySql数据库中检索简单的数据。 当我在浏览器中运行路由器时 – http:// localhost:1337 / getAllChoices ,浏览器似乎挂起。 我在浏览器控制台中也看不到任何错误。 在我的模型文件夹中,我有一个Multiplechoice.js module.exports = { attributes: { multiplechoiceid: { type: 'integer'}, description: { type: 'string'} }, getAllChoices: function(){ return this.description ; } } 我的route.js包含这个:'get / allchoices':'HomeController.GetAllChoices' 我的HomeController包含这个:getallchoices:function(req,res){return MultipleChoice.getAllChoices(); } 我错过了什么吗? 谢谢。

在sails中永远使用时出错

我是帆船的新手。 我发现一些错误,当我运行sails应用程序通过使用' 永远启动app.js –prod ' 我的风格被打破,在控制台中有一个错误, WebSocket connection to 'ws://192.168.1.191/socket.io/?__sails_io_sdk_version=0.11.0&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript&EIO=3&transport=websocket&sid=hFy1TK_-48EQBVIyAAAE' failed: Error during WebSocket handshake: Unexpected response code: 400 但是当我用“ 帆升降机 ”来运行帆时,它通常工作。 如果我通过放弃咕噜声 { "hooks": { "grunt": false } } 在.sailsrc文件中,它通常也工作。 我不知道如何永久运行帆没有禁用咕噜声。 我真的需要帮助。 谢谢。

在Sails.js中使用load-grunt-config

上下文 我已经写了一些咕噜的任务,我想用一个我在Sails.js中编写的新项目来使用它们。 使用Sails.js,你可以添加一个JS文件到/tasks/register文件夹来增加额外的grunt任务。 在我们添加文件之前,让我们来讨论一下这个问题。 问题 帆不会抬起。 debugging器显示: debug: ——————————————————– error: ** Grunt :: An error occurred. ** error: ———————————————————————— ERROR >> Unable to process task. Warning: Required config property "clean.dev" missing. 有问题的问题显然是咕噜,所以然后我尝试grunt build (自动运行与sails lift ): Running "clean:dev" (clean) task Verifying property clean.dev exists in config…ERROR >> Unable to process task. Warning: Required config property […]