我想使用Restangular customGET方法在查询参数中使用特殊字符调用URL .我正在为我的API使用Loopback,它使用方括号进行查询.似乎在Restangular中不允许这样做.
我想调用以下URL.
/api/v1/employees/findOne?filter[where][salesCode]=SC2
Run Code Online (Sandbox Code Playgroud)
或者这个但不确定如何.
/api/v1/employees?filter[where][salesCode]=SC2
Run Code Online (Sandbox Code Playgroud)
我试过跟随没有成功.
Restangular.all("employees").customGET("findOne", {filter + "%5Bwhere%5D%5BsalesCode%5D": newValue});
Run Code Online (Sandbox Code Playgroud)
和
Restangular.all("employees").customGET("findOne", {filter[where][salesCode]: newValue});
Run Code Online (Sandbox Code Playgroud)
作为一个我正在使用的工作,$http但黑客是一天的黑客.
我正在尝试将StrongLoop Loopback [后端]与Yeoman工作流[前端]集成,但努力将两个代码库联合起来.我知道我可以使用StrongLoop的Loopback独立开发我的"后端",并将其作为REST API公开.但是,我宁愿开发使用Loopback Angular SDK并在同一个应用程序中以编程方式连接到模型.我想知道我需要如何组织我的文件夹结构,更新我的Gruntfile.js以包括服务和构建函数的Loopback应用程序设置,并且只运行一个服务器实例进行开发(而不是"grunt serve"用于我的yeoman应用程序前端东西和"slc run"用于环回后端的东西).
我已经阅读了有关yeoman脚手架的"计划",而不是Loopback的CLI工作流程,但是他们在Github上的5个月+没有任何更新.
任何使其现在有效的指导(而不是等待开发此功能)将不胜感激.
供参考:以下是带有Grunt命令的Loopback Angular SDK说明 http://docs.strongloop.com/display/DOC/AngularJS+JavaScript+SDK
我想指定2个mssql表之间的关系.Paymentcategory和支付.paymentcategory.id加入payout.category列.
在payout.json模型中我指定为foreignKey:id,
"relations": {
"paymentcategories": {
"type": "hasOne",
"model": "Paymentcategory",
"foreignKey": "id"
}
Run Code Online (Sandbox Code Playgroud)
但是对于id字段,loopback默认为primaryKey
有没有办法在类别字段上指定连接.最好在common/models/payout.json文件中?
"relations": {
"paymentcategories": {
"type": "hasOne",
"model": "Paymentcategory",
"foreignKey": "id",
"primaryKey": "category" ??????????????????
}
Run Code Online (Sandbox Code Playgroud)
现在我收到这个错误:
"error": {
"name": "Error",
"status": 400,
"message": "Key mismatch: Paymentpayout.id: undefined, Paymentcategory.id: 1",
"statusCode": 400,
Run Code Online (Sandbox Code Playgroud) 乍一看,他们似乎做同样的事情:定义一对多的关系所以为什么你会选择一个或另一个?
我正在使用Loopback Framework,做一个web项目.但我认为我在这里暴露的问题与此关系不大,但具有一般的Javascript/Node.JS知识.
在代码的一部分,我正在做:
roleMapping.find({
where: {
principalType: 'USER',
principalId: context.principals[0].id
},
include: 'role'
}, function(err, roles){
console.log(roles[0]);
for (var i in roles)
{
if (roles[i].role.name === 'teamLeader' &&
roles[i].groupId === context.modelId)
{
cb(null,true);
}else {
cb(null,false);
}
}
});
Run Code Online (Sandbox Code Playgroud)
好的,但是在尝试比较时失败了roles[i].role.name.所以,我记录了roles[i]对象包含的内容.
{ groupId: 1,
id: 3,
principalType: 'USER',
principalId: 1,
roleId: 2,
role:
{ id: 2,
name: 'teamLeader',
description: 'The leader(s) of a team',
created: null,
modified: null } }
Run Code Online (Sandbox Code Playgroud)
好吧,没有错,但它仍然失败,所以我试图打印role属性.令我惊讶的是:
{ [Function]
update: [Function], …Run Code Online (Sandbox Code Playgroud) 我使用Loopback框架开发了一个API,因为我必须insert or update使用一个表.
我的表如下所示:
userid bbid saved id(PK)
1 5 1000 1
Run Code Online (Sandbox Code Playgroud)
所以当下次if(bbid = 5)时它应该更新上面的行,如果没有bbid = 5那么它应该插入上面的表中.
我尝试了以下方法:
app.models.modelname.upsert({
bbid: bb.id,
saved: Saved,
userid: 1
}, function(err, res) {});
Run Code Online (Sandbox Code Playgroud)
编辑COMPOSITE ID:
app.models.modelname.upsert({
bbid: vvvv.bbid,
userid: 1,
saved: amountSaved
}, function(err, res) {});
Run Code Online (Sandbox Code Playgroud)
它也说过了Loopback doc
upsert - checks if the instance (record) exists, based on the designated
ID property, which must have a unique value; if the instance already exists,
the method updates that instance. Otherwise, it inserts a …Run Code Online (Sandbox Code Playgroud) 是否有一个表单使环回自动验证远程方法中的输入参数?
我们假设我们有一个远程方法的以下定义:
WebuserModel.remoteMethod('overLogin', {
description: "Performs a Webuser's login to the system",
accepts: [
{
arg: 'credentials', type: {
"username": { type: "string", required:true },
"password": { type: "string", required: true }
},
http: {source: 'body'},
required: true
},
],
returns: {arg: 'accesToken', type: "object", root: true},
http: {path: '/login', verb: 'post'}
}
Run Code Online (Sandbox Code Playgroud)
我希望loopback能够在每个请求上执行输入参数的验证,并在传递的对象不符合定义的模式(具有两个强制属性的强制对象)时引发错误.
显然它不会发生.任何线索?
我已经设置了Loopback项目并安装了运行我的项目所需的其他软件包.每当我尝试使用文件夹中的命令运行应用程序时
node .
Run Code Online (Sandbox Code Playgroud)
它引发了以下错误:
test_app/node_modules/strong-remoting/lib/shared-method.js:157
if (/^prototype\./.test(name)) {
^
RangeError: Maximum call stack size exceeded
Run Code Online (Sandbox Code Playgroud)
关于这个错误,我几乎不知道.你能建议任何解决方案吗?
我正在使用loopback 3构建REST服务,我想使用async/await而不是必须使用回调.所以不要这样做:
MyModel.myFunction = (callback) => {
MyModel.find({where: {id: 2}}, (e, data) => {
if (e) return callback(e);
callback(null, data);
});
};
Run Code Online (Sandbox Code Playgroud)
我更喜欢这样做:
MyModel.myFunction = async (callback) => {
try {
const data = await MyModel.find({where: {id: 2}});
callback(null, data);
} catch (e) {
console.error(e);
callback(e);
}
};
Run Code Online (Sandbox Code Playgroud)
回调方法完美无缺 - async/await会产生很多错误:
UnhandledPromiseRejectionWarning: Error: Callback was already called.UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by …loopbackjs ×10
node.js ×5
javascript ×4
angularjs ×3
strongloop ×2
async-await ×1
ecmascript-6 ×1
gruntjs ×1
restangular ×1
upsert ×1
yeoman ×1