2016-06-22 7 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'} 
} 
); 

私はループバックエクスプローラでこの方法を試したとき、私はこの「AssertionErrorが」

enter image description here

答えて

2

を参照してくださいあなたの問題は、不正な引数によるものでなければなりませんSync.find()メソッドに渡されます。 (成功シナリオとエラーシナリオの2つの機能を提供しています)。 によると、永続化モデルのfind関数には2つの引数があります。オプションのフィルターオブジェクトとコールバックが含まれています。コールバックでは、ノードerror-firstスタイルが使用されます。

以下のようなものにあなたの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

ありがとう!働いた! :) –

関連する問題