$(#scan_Now).onClick = function(){
/* var myArray=new Array();
myArray[0] = $(#aaTestID_1).checked;
myArray[1] = $(#aaTestID_2).checked;
myArray[2] = $(#aaTestID_3).checked;
myArray[3] = $(#aaTestID_4).checked;
myArray[4] = $(#aaTestID_5).checked;
myArray[5] = $(#aaTestID_6).checked;
myArray[6] = $(#aaTestID_7).checked;
myArray[7] = $(#aaTestID_8).checked;
myArray[8] = $(#aaTestID_9).checked;
myArray[9] = $(#aaTestID_10).checked;
myArray[10] = $(#aaTestID_11).checked;
myArray[11] = $(#aaTestID_12).checked;
for(var i = 0; i<myArray.length;i++)
{
view.CallCbc(myArray[i]); //这是重点。把数据传入后端
stdout.println(myArray[i]);
}*/
//一次性发送结果到后端
$(#scan_Now).onClick = function(){
$(#regis_70_2).style["display"] = "block";
$(#regis_70_1).style["display"] = "none";
var iParam = 0;
// var myArray=new Array();
if($(#aaTestID_1).checked)
{
iParam |= 1<<0;
}
if($(#aaTestID_2).checked)
{
iParam |= 1<<1;
}
if($(#aaTestID_3).checked)
{
iParam |= 1<<2;
}
if($(#aaTestID_4).checked)
{
iParam |= 1<<3;
}
if($(#aaTestID_5).checked)
{
iParam |= 1<<4;
}
if($(#aaTestID_6).checked)
{
iParam |= 1<<5;
}
if($(#aaTestID_7).checked)
{
iParam |= 1<<6;
}
if($(#aaTestID_8).checked)
{
iParam |= 1<<7;
}
if($(#aaTestID_9).checked)
{
iParam |= 1<<8;
}
if($(#aaTestID_10).checked)
{
iParam |= 1<<9;
}
if($(#aaTestID_11).checked)
{
iParam |= 1<<10;
}
if($(#aaTestID_12).checked)
{
iParam |= 1<<11;
}
stdout.println("param :" + iParam);
view.CallCbc(iParam);
};
};
代码优化 html与后端交互代码优化/。上面的代码都是第一代:
$(#scan_Now).onClick = function(){
$(#regis_70_2).style["display"] = "block";
$(#regis_70_1).style["display"] = "none";
var iParam = 0;
var secChk1 = $(#second_chk_1);
var chk = secChk1.$$(input); //拿到整个div里面带input属性的控件存入数组,本身就是数组
var sum = 0; //筛选判断条件
var j = 0;
for( var tmpv in chk)
{
if(tmpv.checked != false)
{
iParam |= 1 << j;
stdout.println(j);
}
j++;
}
stdout.println(iParam);
view.CallCbc(iParam);
};
前段代码。复选框的操作;
后端:.h函数的声明
BEGIN_FUNCTION_MAP
FUNCTION_1("CallCbc", CallC);
END_FUNCTION_MAP
sciter::value CallC(sciter::value Bool_att);
.cpp函数里面的操作
//复选框取状态
sciter::value Mysciter::CallC(sciter::value Bool_att)
{
//bool check_box = Bool_att;
sciter::value Bool_att1 = Bool_att; //d选中是1.没有就是0
这里是一次一次的获取,前端页能一次性获取
return Bool_att1;
}
未完;

本文介绍了一种前端与后端交互代码的优化方案,通过使用位运算来压缩多个复选框的状态信息,减少数据传输量。同时展示了如何从前端一次性发送结果到后端的方法,并提供了后端处理这些数据的示例。
1079

被折叠的 条评论
为什么被折叠?



