这是我的JS文件
window.$ = window.jQuery = WLJQ;
function wlCommonInit() {
}
$(document).ready(function(){
$("#search").click(function(){
GetMedicine();
});
});
window.e='';
var univ;
function GetMedicine() {
var medicine= $("#medicine").val();
var location=$("#location").val();
alert(medicine);
var invocationData = {
adapter : 'ATM',
procedure : 'getMedicineDetails1',
parameters: [medicine,location]
};
WL.Client.invokeProcedure(invocationData,{
onSuccess : loadFeedsSuccess,
onFailure : loadFeedsFailure
});
}
function loadFeedsSuccess(result){
window.e=result;
univ=result.invocationResult.resultSet.length;
WL.Logger.debug("loadsfeedssuccess");
if (result.invocationResult.resultSet.length>0)
{
var invocationData={
adapter : 'ATM',
procedure : 'checkCount',
parameters: []
};
WL.Client.invokeProcedure(invocationData,{onSuccess:countgreater});
}
else
{
loadFeedsFailure1();
}
}
function countgreater(result){
if(result.invocationResult.resultSet.length>0)
{
alert("entered count greater");
var c=result.invocationResult.resultSet[0].num;
if(c>=0)
{
invocationData={
adapter : 'ATM',
procedure : 'getStoreDetails',
parameters: [e[c].RegNo]
};
WL.Client.invokeProcedure(invocationData,{onSuccess:displayAgain});
}
else
{
invocationData2={
adapter : 'ATM',
procedure : 'deleteQuery',
parameters: []
};
WL.Client.invokeProcedure(invocationData2);
}
}
}
ADAPTER JS
var selectStatement = WL.Server.createSQLStatement("select * from medicine WHERE Name= ? ");
var selectStatement2 = WL.Server.createSQLStatement("select LocId from location WHERE LocName= ? ");
var selectStatement4 = WL.Server.createSQLStatement("select RegNo from stormedavl where MedId=? AND Availability=true");
var selectStatement5 = WL.Server.createSQLStatement("select * from store WHERE RegNo=? ");
var selectStatement6 = WL.Server.createSQLStatement("select RegNo from stormedavl where LocId=? AND (MedId=? AND Availability=true)");
var selectStatement7 = WL.Server.createSQLStatement("insert into querycheck values (?)");
var selectStatement8 = WL.Server.createSQLStatement("select * from querycheck");
var selectStatement9 = WL.Server.createSQLStatement("update querycheck set num=?");
var selectStatement10 = WL.Server.createSQLStatement("delete from querycheck");
var selectStatement11 = WL.Server.createSQLStatement("insert into alertcheck values(?)");
var selectStatement12 = WL.Server.createSQLStatement("select * from alertcheck");
var selectStatement13 = WL.Server.createSQLStatement("delete from alertcheck");
function getMedicineDetails1(Name,Location) {
var a=getMedicineDetails(Name);
var MedId=a.resultSet;
var b=getLocId(Location);
var LocId=b.resultSet;
var d,f,g;
if(a.resultSet.length>0)
{
d=getFinal(LocId[0].LocId,MedId[0].MedId);
e=d.resultSet;
if(e && e.length>0)
{
var len=e.length-1;
var r=insertQueryCheck((len));
if(r.updateStatementResult.updateCount>0)
return d;
}
else
{
f=WL.Server.invokeSQLStatement({
preparedStatement : selectStatement4,
parameters : [MedId[0].MedId]
});
if(f.resultSet.length>0)
{
g=f.resultSet;
insertQueryCheck(f.resultSet.length);
return f;
}
}
else
{
WL.Server.invokeSQLStatement({
preparedStatement : selectStatement11,
parameters : [1]
});
return f;
}
}
}
else
{
WL.Server.invokeSQLStatement({
preparedStatement : selectStatement11,
parameters : [0]
});
return a;
}
}
function getMedicineDetails(Name) {
return WL.Server.invokeSQLStatement({
preparedStatement : selectStatement,
parameters : [Name]
});
}
function getLocId(Location) {
return WL.Server.invokeSQLStatement({
preparedStatement : selectStatement2,
parameters : [Location]
});
}
function getStoreDetails(RegNo) {
return WL.Server.invokeSQLStatement({
preparedStatement : selectStatement5,
parameters : [RegNo]
});
}
function insertQueryCheck(Length) {
return WL.Server.invokeSQLStatement({
preparedStatement : selectStatement7,
parameters : [Length]
});
}
function checkCount()
{
return WL.Server.invokeSQLStatement({
preparedStatement : selectStatement8,
parameters : []
});
}
function updateCount(len)
{
return WL.Server.invokeSQLStatement({
preparedStatement : selectStatement9,
parameters : [len]
});
}
function deleteQuery()
{
return WL.Server.invokeSQLStatement({
preparedStatement : selectStatement10,
parameters : []
});
}
我希望通过将后果函数分配给全局变量“e”,将返回的resultSet分配给loadFeedsuccess。我无法这样做。当我在countgreater函数中读取e [c] .RegNo时,它显示错误无法从undefined中读取RegNo。有办法吗?
答案 0 :(得分:0)
也许替换:
e[c].RegNo
使用:
e.invocationResult.resultSet[c].RegNo
如果这不起作用,只需添加日志语句,找出所需值的正确路径。例如:
alert(JSON.stringify(e))
或
console.log(JSON.stringify(e))
或
WL.Logger.debug(JSON.stringify(e))
在loadFeedsSuccess
和countgreater
个函数中。