2016-06-22 5 views
4

루프백을 사용하여 API를 생성하고 AngularJS와 통신했습니다. (- timeChanged 긴) 및 모든 레코드를 반환해야 내 sync.js 모델 파일에루프백 레코드 배열을 반환하는 원격 메서드

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라는 모델을 가지고 같거나 동일한 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'} 
} 
); 

내가 인해 잘못된 인수에 내가

enter image description here

답변

2

귀하의 문제가해야이 "AssertionError를"을 참조하십시오 루프백 탐색기에서이 방법을 시도 할 때 Sync.find() 메서드에 제공됩니다. (성공 및 오류 시나리오에 대해 2 가지 기능을 제공했습니다). Strongloop documentation에 따라, 지속 모델의 find 함수에는 두 개의 인수가 있습니다. 선택적 필터 객체 및 콜백. 콜백은 노드 오류 우선 스타일을 사용합니다.

은 다음과 같은 것을에 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); 
}); 
+0

감사합니다! 일했다! :) –