我从 javascript 方法“caller”调用 PageMethod“SameMethod”,这样我就可以从数据库中获取一些值。在我获得值后,控制在“onSuccess”方法中继续。问题是我需要在“onSuccess”方法中使用来自 javascript 方法“caller”的一些变量值(“importantValue”)。
function caller(){ var importantValue = 1984; PageMethod.SomeMethod(param1,..., onSuccess, onFailure) }
onSuccess 方法应该是这样的:
function onSuccess(pageMethodReturnValue, importantValue ){ }
是否可能,如果可以,如何将多个参数(除了页面方法的返回值)传递给 PageMethod 的“onSuccess”方法?
感谢帮助
最佳答案
调用 PageMethod 时将您的 importantValue
作为附加参数传递。 (如果您在线搜索更多信息,这通常称为上下文参数)
function caller(){
var importantValue = 1984;
PageMethod.SomeMethod(param1,..., onSuccess, onFailure, importantValue)
}
然后您可以按如下方式访问 onSuccess 回调中的值:
function onSuccess(pageMethodReturnValue, context, methodName){
// context == 1984
}
更新 以解释@JacksonLopes 的 onSuccess 参数 aspalliance website in an article by Suresh Kumar Goudampally 上有很好的描述
重要的一点(修改为使用我的参数名称)是:
The success call back method has three parameters:
- pageMethodReturnValue - Returns the output of the page method.
- context - This is used to handle different logic when single callback is used for multiple page method requests. We can also pass an array of values as the
context
parameter.- methodName - This parameter returns the name of page method called.
关于javascript - 我们如何将多个参数传递给 PageMethod 的 onSuccess 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4398243/