我试图了解MFP JSONStore& HTTP适配器工作。我下载了源代码here。我按照步骤构建应用程序。我还部署了这个适配器here。但是当我试图将脏数据推送到适配器时,我注意到了。适配器仍然记录未定义。
这是推送功能代码:
function pushToAdapter(){
alert("pushToAdapter");
try {
WL.JSONStore.get(collectionName).push().then(function (res) {
if(Array.isArray(res) && res.length < 1){ // I changed this to res.length > 1
document.getElementById("resultsDiv").innerHTML = "Documents Pushed Successfuly";
} else {
document.getElementById("resultsDiv").innerHTML = "Failed To Push Documents to Adapter: "+ res[0].errorObject;
}
}).fail(function (errorObject) {
alert(errorObject.msg);
});
} catch (e) {
alert("Failed To Push Documents to Adapter");
}
}
&安培;这是适配器代码:
function pushPeople(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: pushPeople called.');
MFP.Logger.debug('Got data from JSONStore to ADD: ' + JSON.stringify(data)); //always undefined
return;
}
function addPerson(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: addPerson called.');
MFP.Logger.debug('Got data from JSONStore to ADD: ' + JSON.stringify(data)); //always undefined
return;
}
function removePerson(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: removePerson called.');
MFP.Logger.debug('Got data from JSONStore to REMOVE: ' + JSON.stringify(data)); //always undefined
return;
}
请注意,我使用的是修补版本的cordova-plugin-mfp-jsonstore。除了第5238行(如下)之外,它与this version相同:
resourceRequest = new WLResourceRequest('adapters/' + invocationData.adapter + '/' + invocationData.procedure, WLResourceRequest.POST);
resourceRequest.setHeader('Content-Type','application/x-www-form-urlencoded'); //patched version
resourceRequest.send().then(ipOpts.onSuccess, ipOpts.onFailure);