2015-10-01 146 views
1

根據文檔,您可以創建自定義響應類; https://docs.strongloop.com/display/public/LB/Remote+methods#Remotemethods-Argumentdescriptionsstrongloop,如何定義自定義端點的響應類

我使用的遠程方法的描述是:

公共/模型/產品-sku.js

ProductsSku.remoteMethod( 'getSomeData', { http: {path: '/getSomeData', verb: 'get'}, accepts: {arg: 'filter', type: 'object', http: { source: 'query'} }, returns: { arg: 'id', description: 'Custom endpoint', type: 'CustomProductType', root: true } } );

在同一個文件中我對CustomProductType的定義;

var CustomProductType: { id: Number, name: String, ... };

現在,如果我打開響應類被定義爲CustomProductType的資源管理器,但有在/資源管理器/資源/ ProductsSku招搖定義無模型定義(這仍然是招搖1.2)

作爲這不是一個實際的模型,我如何註冊/定義模型,以便它與api定義一起發送。

== 我曾嘗試:

通用/模型/產品-sku.js:

var DataSource = require('loopback-datasource-juggler').DataSource; var ds = new DataSource('memory'); ds.define('CustomProductType', CustomProductType);

存儲數據源是因爲它不是一個實際的模型。

回答

2

由於這不是在文檔中,這是我做的。

添加你喜歡的remoteMethod定義 我與type: 'CustomProductType'

轉到服務器/模型config.json文件上面做了迴應類的名稱,並添加類型有

"CustomProductType": { "dataSource": false, "public": true }

現在將您的模型定義添加到common/models/custom_product_type.json