0

ループバック モデル用の拡張 API を作成しようとしています

以下のドキュメントを使用して、http://docs.strongloop.com/display/LB/Extend+your+API

しかし、 MainReview.count()のようなループバックによって提供されるカスタム関数を使用できません。

module.exports = function(MainReview){


    MainReview.greet = function(msg, cb) {
      var MainReview = this;
      cb(null, 'Greetings... ' + **MainReview.count()** );
    }

    MainReview.remoteMethod(
        'greet', 
        {
          accepts: {arg: 'msg', type: 'Object'},
          returns: {arg: 'greeting', type: 'string'}
        }
    );
};

私はそれをグーグルで試しましたが、助けにはなりませんでした。

4

1 に答える 1

1

MainReview.count() は非同期であり、コールバック関数を受け取る必要があることに注意してください。コードは次のように修正できます。

module.exports = function(MainReview){


    MainReview.greet = function(msg, cb) {
      var MainReviewModel = this;
      MainReviewModel.count(function(err, result) {
        cb(err, 'Greetings... ' + result );
      }); 
    }

    MainReview.remoteMethod(
        'greet', 
        {
          accepts: {arg: 'msg', type: 'Object'},
          returns: {arg: 'greeting', type: 'string'}
        }
    );
};
于 2014-08-26T15:36:25.600 に答える