LoopBack Remote Method返回记录数组
发布时间:2020-12-17 07:14:48 所属栏目:安全 来源:网络整理
导读:我使用loopback生成我的api和AngularJS来与它通信.我有一个名为Sync的模型,其中包含以下记录: Sync": {"34": "{"uuid":"287c6625-4a95-4e11-847e-ad13e98c75a2","table":"Property","action":"create","timeChanged":1466598611995,"id":34
我使用loopback生成我的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","action":"update","timeChanged":1466598625506,"id":35}","36": "{"uuid":"176aa537-d000-496a-895c-315f608ce494","timeChanged":1466598649119,"id":36}" } 在我的sync.js模型文件中我试图编写以下接受数字的方法(long – 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'} } ); 当我在loopback explorer中尝试这个方法时,我看到这个“AssertionError” 解决方法
您的问题必须是由于提供给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); }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |