DWR 3.0版本:
1.传递额外的参数
Rules:
- arg - If specified will be used as a default argument to pass to the callback and will apply to both callback handlers and exception handlers. 如果设置该参数则会作为一个默认的参数传递给回调函数和错误处理函数
- callbackArg - If specified will apply to callback handlers and will override arg.如果设置该参数则会传递给回调函数,会覆盖arg的设置
- exceptionArg - If specified will apply to exception handlers and will override arg.如果设置该参数则会传递给错误处理函数,会覆盖arg的设置
示例:
var dataFromBrowser = ...;
var dataFromBrowser2 = ...;
var callMetaData = {
callback:callbackFunction,
arg: dataFromBrowser, // specify an argument to pass to the exeptionHandler
callbackArg: dataFromBrowser2, // overrides args will be passed to the callback
exceptionHandler: exceptionHandlerFunction
};
Remote.method(params, callMetaData);
function callbackFunction(dataFromServer, arg1) {
// you will now have access to dataFromBrowser2 as arg1
// callbackArg overrides arg
}
function exceptionHandlerFunction(exceptionMessage, exception, arg1) {
// you will now have access to dataFromBrowser1 as arg1
// arg also applies to exceptionHandlers
}
2.作用域
Rules:
- scope - If specified will be used as the default scope and will apply to both callback handlers and exception handlers.回调函数和错误处理函数的作用域
- callbackScope - If specified will apply to callback handlers and will override scope.回调函数的作用域,覆盖scope的设置
- exceptionScope - If specified will apply to exception handlers and will override scope.错误处理函数的作用域
,覆盖scope的设置
Note: The default scope is window. 默认作用域是window
示例:
(function() {
someObject = {};
someObject.privateVar = "Private variable from the main object.";
someObject.callbackFunction = function(dataFromServer) {
alert(this.privateVar);
// The preceding line will alert the value of privateVar.
// The key here is the use of 'this'. The scope is not
// lost because it is specified in the call-meta data object
// and used to execute the callback function.
}
})();
var callMetaData = {
callback:someObject.callbackFunction,
scope: someObject
};
Remote.method(params, callMetaData);
DWR3.0之前的版本:
用闭包来实现,如下示例:
var dataFromBrowser = ...;
// define an erasure function to store a reference to
// dataFromBrowser and to call dataFromServer
var callbackProxy = function(dataFromServer) {
callbackFunc(dataFromServer, dataFromBrowser);
};
var callMetaData = { callback:callbackProxy };
Remote.method(params, callMetaData);
原文:http://directwebremoting.org/dwr/browser/extra-data.html
分享到:
相关推荐
DWR 取得回调函数返回值案列DWR 取得回调函数返回值案列DWR 取得回调函数返回值案列
包涵了DWR3.0的JAR包,DWR3.0的说明文档,通俗易懂。
dwr dwr包 dwr3.0文档 dwr3.0.jar
dwr3.0.jar
这个项目中,详细介绍了dwr3.0+SSH2的配置,包含全部jar包及sql文件
DWR3.0官方中文入门教程,和dwr3.0安装文件。
最新dwr3.0的包,有需要的朋友就下载吧
dwr3.0以及相关中文文档
dwr3.0文档和jar包。文档是英文原版。
DWR3.0.jar、DWR的实例war和DWR2.0中文说明文档
dwr3.0的搭建与基本的介绍,希望可以给初学者带来帮助
dwr3.0.zip包括dwr3.0的jar包和war运行文件,方便下载
网上的资源很多都是2.0的,将dwr官网的Clock实现,简单明了。是使用反向Ajax的好用的参考例子,配置文件全。
DWR3.0 全部文件 包括文档 很实用哦
dwr回调函数里面怎么得到list信息,这儿有详解的办法
NULL 博文链接:https://liuningbo.iteye.com/blog/1131111
去年翻译了一部分,放在硬盘里,一直没拿出来。工作了,只能先把它放这搁一下了. java流行框架. 希望热心的朋友联系我,一起交流,完成她的翻译工作, 博客 http://hi.baidu.com/passedbylove qq:13019940
dwr3.0的web.xml的配置文件,该文件是从dwr.jar文件中拷贝出来的
dwr3.0.rar