Loopback AngularJS SDK - 查询相关机型

Loopback AngularJS SDK - query related models

环回文档指出 AngularJS "SDK creates a Category.products() method that can be used to list all products in a given category."

$scope.products = Category.products({
    id: $scope.category.id,
});

这很好用,但是,我如何return 列出包含所有相关产品的所有类别。我已经阅读了文档和源代码核心 (lb-services.js),但看不到如何执行此操作。

有什么想法吗?

解决了。 您需要在父模型中创建一个远程方法(确保您已经设置了模型之间的关系)。

Supplier.supplierServices = function (cb) {
    var response;
    Supplier.find({include: 'Services'}, function (err, suppliers) {
        console.log('err', err, 'suppliers', suppliers);
        response = suppliers;
        cb(null, response);
    });
};

然后 运行 lb-ng 将 api 暴露给 angular SDK。然后您可以从客户端调用远程方法。