Javascript 在sql适配器过程中使用WL.Server.invokeSQLStatement返回的resultset
我想在过程本身的SQL适配器过程中使用通过Javascript 在sql适配器过程中使用WL.Server.invokeSQLStatement返回的resultset,javascript,ibm-mobilefirst,worklight-adapters,Javascript,Ibm Mobilefirst,Worklight Adapters,我想在过程本身的SQL适配器过程中使用通过WL.Server.invokeSQLStatement调用SQL语句返回的resultSet 我尝试了我们通常使用的方法,在SQL适配器过程中使用result.invocationResult.resultSet[variable].Property,但它不起作用 HTML 在Chrome上,我得到以下错误 过程调用错误。Ecma错误:类型错误:无法读取 来自未定义的属性“resultSet” (E%3A%5CPRACTICE%5CATM%5Cadap
WL.Server.invokeSQLStatement
调用SQL语句返回的resultSet
我尝试了我们通常使用的方法,在SQL适配器过程中使用result.invocationResult.resultSet[variable].Property
,但它不起作用
HTML
在Chrome上,我得到以下错误
过程调用错误。Ecma错误:类型错误:无法读取
来自未定义的属性“resultSet”
(E%3A%5CPRACTICE%5CATM%5Cadapters%5CATM/ATM impl.js#25)。我的电话号码是25
是var a=result.invocationResult.resultSet
尝试将适配器JavaScript实现改为以下内容 我用不同的表和变量尝试了一个版本,它对我很有效(至少是Worklight Studio中的适配器调用) 注意我是如何使用
locId.resultSet
而不是locId.invocationResult.resultSet
。后者用于客户端,而前者用于服务器端
还要注意两个函数的分离
function getStudentInfos(Name,Location) {
var locId, a, b;
locId = getlocId(Location);
a = locId.resultSet;
if (a && a.length>0) {
b = a[0].LocId;
}
return WL.Server.invokeSQLStatement({
preparedStatement : selectStatement3,
parameters : [b]
});
}
function getlocId (Location) {
var result = WL.Server.invokeSQLStatement({
preparedStatement : selectStatement2,
parameters : [Location]
});
return result;
}
注意
if
语句。。。确保在那里添加一些错误处理…不起作用。。。太好了。:)你是在什么环境下尝试的?这是一个技术QA和网站。添加代码片段,添加您遇到的任何错误。在预览应用程序时打开Chrome开发工具,你会看到什么?请将此信息添加到问题中。我已修改了我的问题。能否提供SQL脚本来重新创建数据库?(请注意,我将使用MySQL,而不是DB2…如果这是您的数据库类型)我的数据库的名称是“MedPurge”,它包含两个表1)位置2)storeloc,这些表在上述问题中是参考的。位置表具有以下属性LocId(主键)varchar 10,LocName varchar 40。storeloc表具有两个属性RegNo(主键)varchar30,LocId VARCHAR10查看我答案的左侧…它显示了一个V标记。单击它。是的,我这样做了。谢谢。你能帮我回答我问的第二个问题吗?这里是链接@user3476186,你的第二个问题中现在有一个答复。查看它。
window.$ = window.jQuery = WLJQ;
function wlCommonInit() {
}
$(document).ready(function(){
$("#search").click(function(){
GetEmployeeData();
});
});
function GetEmployeeData() {
var medicine= $("#medicine").val();
var location=$("#location").val();
alert(medicine);
var invocationData = {
adapter : 'ATM',
procedure : 'getStudentInfos',
parameters: [medicine,location]
};
WL.Client.invokeProcedure(invocationData,{
onSuccess : loadFeedsSuccess,
onFailure : loadFeedsFailure
});
}
function loadFeedsSuccess(result){
alert("Hii");
WL.Logger.debug("Feed retrieve success");
if (result.invocationResult.resultSet.length>0)
displayFeeds(result.invocationResult.resultSet);
else
loadFeedsFailure();
}
function loadFeedsFailure(result){
alert("H");
}
function displayFeeds(items){
alert("ii");
var table = document.getElementById("myTable");
for(var i=0;i<items.length;i++)
{
// Create an empty <tr> element and add it to the 1st position of the table:
var row = table.insertRow(i+1);
var cell1 = row.insertCell(0);
// Add some text to the new cells:
cell1.innerHTML = items[i].RegNo;
}
}
function LoadResultPage() {
$("AppDiv").hide();
$("#itemsList").show();
};
var selectStatement2 = WL.Server.createSQLStatement("select LocId from location WHERE LocName= ? ");
var selectStatement3 = WL.Server.createSQLStatement("select RegNo from storeloc WHERE LocId= ? ");
function getStudentInfos(Name,Location) {
var result=WL.Server.invokeSQLStatement({
preparedStatement : selectStatement2,
parameters : [Location]
});
var a = result.invocationResult.resultSet;
if(a.length>0)
var LocId=a[0].LocId;
return WL.Server.invokeSQLStatement({
preparedStatement : selectStatement3,
parameters : [LocId]
});
}
function getStudentInfos(Name,Location) {
var locId, a, b;
locId = getlocId(Location);
a = locId.resultSet;
if (a && a.length>0) {
b = a[0].LocId;
}
return WL.Server.invokeSQLStatement({
preparedStatement : selectStatement3,
parameters : [b]
});
}
function getlocId (Location) {
var result = WL.Server.invokeSQLStatement({
preparedStatement : selectStatement2,
parameters : [Location]
});
return result;
}