gpt4 book ai didi

LoopBack 远程方法返回记录数组

转载 作者:行者123 更新时间:2023-12-04 20:34:43 25 4
gpt4 key购买 nike

我使用环回来生成我的 api 和 AngularJS 来与之通信。我有一个模型叫 Sync包含以下记录:

Sync": {
"34": "{\"uuid\":\"287c6625-4a95-4e11-847e-ad13e98c75a2\",\"table\":\"Property\",\"action\":\"create\",\"timeChanged\":1466598611995,\"id\":34}",
"35": "{\"uuid\":\"287c6625-4a95-4e11-847e-ad13e98c75a2\",\"table\":\"Property\",\"action\":\"update\",\"timeChanged\":1466598625506,\"id\":35}",
"36": "{\"uuid\":\"176aa537-d000-496a-895c-315f608ce494\",\"table\":\"Property\",\"action\":\"update\",\"timeChanged\":1466598649119,\"id\":36}"
}

在我的 sync.js 模型文件中,我试图编写以下方法,该方法接受数字(长 - timeChanged)并且应该返回具有相等或相等 timeChanged 字段的所有记录。

这是我所在的位置:
Sync.getRecodsAfterTimestamp = function(timestamp, cb){
var response = [];
Sync.find(
function(list) {
/* success */
// DELETE ALL OF THE User Propery ratings associated with this property
for(i = 0; i < list.length; i++){
if(list[i].timeChanged == timestamp){
response += list[i];
console.log("Sync with id: " + list[i].id);
}
}
cb(null, response);
},
function(errorResponse) { /* error */ });
}

Sync.remoteMethod (
'getRecodsAfterTimestamp',
{
http: {path: '/getRecodsAfterTimestamp', verb: 'get'},
accepts: {arg: 'timeChanged', type: 'number', http: { source: 'query' } },
returns: {arg: 'name', type: 'Array'}
}
);

当我在环回资源管理器中尝试此方法时,我看到此“AssertionError”

enter image description here

最佳答案

您的问题一定是由于提供给 Sync.find() 方法的参数不正确。 (您已经为成功和错误场景提供了 2 个函数)。根据 Strongloop documentation ,持久模型的 find 函数有 2 个参数,即。一个可选的过滤器对象和一个回调。回调使用节点错误优先的风格。

请尝试将您的 Sync.find() 更改为如下所示:

Sync.find(function(err, list) {
if (err){
//error callback
}
/* success */
// DELETE ALL OF THE User Propery ratings associated with this property
for(i = 0; i < list.length; i++){
if(list[i].timeChanged == timestamp){
response += list[i];
console.log("Sync with id: " + list[i].id);
}
}
cb(null, response);
});

关于LoopBack 远程方法返回记录数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37971111/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com