在 JS HTTP 适配器中为 MobileFirst 8 添加参数
Add parameters in JS HTTP Adapters for MobileFirst 8
我正在尝试使用 JavaScript HTTP 适配器,以便从 Bluemix 中的 Cloudant BD 获取一些数据。为此,我将MFPF8和Ionic2与TypeScript一起使用。
由于我需要从数据库中获取一个我以前不知道其名称的特定文档,因此我需要有一个 HTTP 适配器,让我将文件名作为参数发送。
我有以下适配器实现文件:
function getMenus() {
var input = {
method : 'get',
returnedContentType : 'json',
path : 'menus/_all_docs?descending=true'
};
return MFP.Server.invokeHttp(input);
}
function getSpecificMenu(menuName) {
var input = {
method : 'get',
returnedContentType : 'json',
path : 'menus/'+menuName
};
return MFP.Server.invokeHTTP(input);
}
这是适配器.xml
<mfp:adapter name="menus"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mfp="http://www.ibm.com/mfp/integration"
xmlns:http="http://www.ibm.com/mfp/integration/http">
<displayName>menus</displayName>
<description>menus</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>https</protocol>
<domain>bluemixcloudanthost.com</domain>
<port>443</port>
<connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
<socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
<maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>
<authentication>
<basic/>
<serverIdentity>
<username>user</username>
<password>pass</password>
</serverIdentity>
</authentication>
</connectionPolicy>
</connectivity>
<procedure name="getMenus" secured="false"/>
<procedure name="getSpecificMenu" secured="false"/>
</mfp:adapter>
因此,按照 API 文档,我执行以下操作来调用 ionic 提供程序中的适配器
@Injectable()
export class MenuListingService {
data: any;
constructor() {
console.log('---> Constructing menu list adapter');
this.data = null;
}
load(menuTitle: string) {
console.log('---> Request '+menuTitle+' Menu');
if (this.data) {
// already loaded data
return Promise.resolve(this.data);
}
// don't have the data yet
return new Promise(resolve => {
let menuRequest = new WLResourceRequest("/adapters/menus/getSpecificMenu", WLResourceRequest.GET);
menuRequest.setQueryParameter('menuName', menuTitle);
menuRequest.send().then((response) => {
console.log('---> Current menu response received');
this.data = response.responseJSON.offers;
resolve(this.data);
})
});
}
}
在知识中心阅读时,我发现了一些关于使用查询字符串调用参数表的内容,例如 ?params=['value'],但它在 500 代码中失败。
请记住,我不在办公室,所以我明天将添加一个编辑,为您提供更多信息,包括服务器响应和MFP服务器日志条目。
但是,就目前而言,我所做的有什么问题吗?
看这里: https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/using-the-mfpf-sdk/resource-request/javascript/#setqueryparameter
更具体地说:
JavaScript 适配器使用有序的无名称参数。要将参数传递给 Javascript 适配器,请使用名称 params 设置参数数组:
resourceRequest.setQueryParameter("params", "['value1', 'value2']");
您缺少的是使用"参数"而不是menuRequest.setQueryParameter('menuName', menuTitle);
。
- 正在添加'X'按钮,在文本字段旁边使用javascript
- 如何在映射数组中添加换行符
- 正在将数据主题添加到所有项目
- ZeroClipboard-在复制之前添加到值
- 我可以在json对象中添加一个函数吗
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 正在SharePoint 2013母版页中添加JQuery移动文件
- 如何添加浮动和非浮动,其他
- 添加文字和评论功能更新Div
- 如果使用 lodash 将属性存在于另一个对象中,则向对象添加属性
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- 在函数中添加数组元素的数值
- 如何将歌曲添加到jPlayer
- 在html Select中添加搜索
- Java脚本时间添加
- FabricJs-限制主对象内添加对象的移动区域
- JQuery添加元素需要在我的js之前再次添加JQuery脚本
- 如何在Google柱状图中动态添加行/列
- 在JS HTTP适配器中为MobileFirst 8添加方法
- 在 JS HTTP 适配器中为 MobileFirst 8 添加参数