buffalo 调方法时 参数的类型

<script>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script>

一 :客户端 js 的数组 来 映射 服务器端的 Map 对象 :

首先我们服务器端 有一个java方法 :

/***/ /**
*输入一个map,原封不动的输出来
*
@param arg
*
@return Map
*/

public Mapobject(Maparg) {
return arg;
}


在客户端我们有 这样的 js 代码 :

< scriptlanguage = " javascript " >
varbuffalo
= new Buffalo(endPoint)

functionsendObject()
{
vara
= {} ;
a[Buffalo.BOCLASS]
= " java.util.Map " ;
a[
" a " ] = " A " ;
a[
" b " ] = true ;
a[
" c " ] = 123.4 ;
varu
= {} ;
u[Buffalo.BOCLASS]
= " net.buffalo.demo.simple.User " ;
u.id
= 234 ;
u.name
= " <xmlhere>& " ;
u.age
= 17 ;
u.sex
= false ;
u.memo
= " verybeautiful " ;
a[
" u " ] = u;
buffalo.remoteCall(
" simpleService.object " ,[a],function(reply) {
alert(
" returnusermemo: " + reply.getResult()[ " u " ].memo);
}
);
}

</ script >

注意 这 2 句 :

a[Buffalo.BOCLASS] = " java.util.Map " ;

u[Buffalo.BOCLASS] = " net.buffalo.demo.simple.User " ;


二 :将表单序列化为一个dto对象

首先我们在服务器端有一个dto对象 :

public class User {
privateintid;
privateStringname;
privateintage;
privatebooleansex;
privateStringmemo;

publicUser(){
}




}

接下来我们在客户端有下列代码 :

< scriptlanguage = " javascript " >
varbuffalo
= new Buffalo(endPoint);

functiondoAnotherSubmit()
{
varuserObj
=Buffalo.Form.formToBean("form1","net.buffalo.demo.form.User");
buffalo.remoteCall(
"userService.createUser",[userObj],function(reply){
$(
"form_infomsg").innerHTML="Formhasbeensubmited,usernameis:"+reply.getResult().username;
}
)
}

</ script >

注意这2句 :

varuserObj = Buffalo.Form.formToBean( " form1 " , " net.buffalo.demo.form.User " );

form1表单中 有 User类 中属性 同名 的 表单项 , 这样 userObj 就可以作为在客户端 映射 User 的参数了。

另外 :

$( " form_infomsg " )

可以指页面中 :

< divid = " form_infomsg " style = " color:blue " ></ div >


表示的位置。


三 :数据绑定

首先 我们在服务器端有 这样一个变量 :

public static Listemployees() {
if(employees.size()>0)returnemployees;
employees.add(
newEmployeeBean("1","Greg","Murray"));
employees.add(
newEmployeeBean("2","Greg","Murphy"));
employees.add(
newEmployeeBean("3","George","Murphy"));
employees.add(
newEmployeeBean("4","George","Murray"));
employees.add(
newEmployeeBean("5","Peter","Jones"));
employees.add(
newEmployeeBean("6","Amber","Jones"));
employees.add(
newEmployeeBean("7","Amy","Jones"));
employees.add(
newEmployeeBean("8","Bee","Jones"));
employees.add(
newEmployeeBean("9","Beth","Johnson"));
employees.add(
newEmployeeBean("10","Cindy","Johnson"));
employees.add(
newEmployeeBean("11","Cindy","Murphy"));
employees.add(
newEmployeeBean("12","Duke","Hazerd"));
returnemployees;
}

在客户端我们有 这样的代码 :

varbuffalo = new Buffalo(endPoint);
functiondoCompletion()
{
buffalo.bindReply(
"ajaxService.filterEmployees",[target.value],"names");
}

同时我们在页面中有 :

< TABLEid = " names " border = " 1 " jheight = " 0 " >

结果 :



还有一种形式是 :

buffalo.remoteCall( " simpleService.allLocales " ,[],function(reply) {
/***//**Buffalo.bind("area",reply.getSource());*/
Buffalo.bind(tableId,reply.getResult());
}
)

注意这句

Buffalo.bind(tableId,reply.getResult());

你可能感兴趣的:(JavaScript,C++,c,.net,C#)