使用 cordova 调用 azure 移动应用自定义 api

use cordova to call azure mobile app custom api

我正在使用 cordova azure 移动应用程序插件连接到我的 azure 移动应用程序,我在其中有一个自定义 api 并且我想从 cordova 客户端调用它但带有参数。

我看到了 post How to call a custom function of Azure Mobile Service from Cordova mobile app?

这很有帮助,但它演示了不带参数的调用

我希望在如何配置我的客户端以调用我的自定义 api 并向其发送参数方面得到帮助

我的习惯api就像

[MobileAppController]
    public class AirportsController : ApiController
    {
        public string GetByCode(int Code)
        {
            return Code.ToString();
        }
    }

我的 cordova 客户端应该是这样的:

client = new WindowsAzure.MobileServiceClient('https://MYAZURESITE.azurewebsites.net');
client.invokeApi('Airports/GetByCode', { method: 'GET' }).then(createKeySuccess, createKeyFailure);

那么我可以在哪里设置我的参数值?

您可以设置如下参数:

var options = {
  method: 'GET',
  parameters: {
    param1: 'val1',
    param2: 'val2'
  }
}

client.invokeApi('Airports/GetByCode', options).then(createKeySuccess, createKeyFailure);

参考https://azure.github.io/azure-mobile-apps-js-client/MobileServiceClient.html#invokeApi了解详细API参考。