当按下按钮时,我需要获得复选框的输入值(True / False) [英] I need to get the input value (True/False) of a checkbox when a button is pressed

查看:105
本文介绍了当按下按钮时,我需要获得复选框的输入值(True / False)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用.setName(chk_id)获取复选框的输入值(true / false),当id是我在flexTable cell bycell中引入的行的id时。
但我总是得到e.parameter_undefinedbecouse e.parameter.chk_i is undefined

  var flexTableReg = app.createFlexTable()。setId(flexTableReg)。setBorderWidth(1); 
var check = new Array(lastRow); (var c = 0; c var text = rowsToConfirm($ var $ = $; $ lt; lastRow; r ++){


[r] [c] .toString(); //这里是CELL
flexTableReg.setText(r + 1,c,text);


}
var id = rowsToConfirm [r] [0];
check [r] = app.createCheckBox()。setName(chk _+ id).setId(chk _+ id);
flexTableReg.setWidget(r + 1,lastCol,check [r]);
} // end fors
} // end if

var botMod = app.createButton()。setText(Activar)。setId(botStatus);
var botHandle = app.createServerHandler(changeStatus)。addCallbackElement(verticalPanelAdmin);
botMod.addClickHandler(botHandle);

mainPanelAdmin.add(flexTableReg);
mainPanelAdmin.add(botMod);
verticalPanelAdmin.add(mainPanelAdmin);
absolutePanelAdmin.add(verticalPanelAdmin);
app.add(absolutePanelAdmin);

返回应用;
}

function changeStatus(e){
var ss = SpreadsheetApp.openById(LOGS_SHEET_ID);
var app = UiApp.getActiveApplication();
var datarray = getDataArray();
var lastRow = ss.getLastRow();

for(var i = 0; i <= lastRow; i ++){
try {
var par = e.parameter [chk _+ i];


if(true){
stop_if_true
var row = getRowByID(0,lastRow,i);
ss.getRange(E+ i).setValue(1);
} // end if
} catch(e){e.parameter_undefined// if e.parameterundefined
return app;}
} // end为
返回应用;
};


解决方案

我不知道 var id = rowsToConfirm [r] [0]; 正在返回,但这是您在设置.setName()和.setId()属性时用作原始ID参数的内容。 / p>

当您尝试获取回调函数中的值时,请使用数字 i 参数,以便可能发生冲突。 / p>

其次,复选框的返回值始终是一个字符串,因此请检查'true''false'而不是 true 或 false



希望这会有帮助,

祝好。


I want to get the input value (true/false) of a checkbox with .setName(chk_id), when id is the id of the row which i have introduced in flexTable cell bycell. But i always get "e.parameter_"undefined"" becouse e.parameter.chk_i is "undefined"

var flexTableReg = app.createFlexTable().setId("flexTableReg").setBorderWidth(1);
var check = new Array(lastRow);

for(var r = 0; r < lastRow; r++){
  for(var c = 0; c < lastCol; c++){
    var text = rowsToConfirm[r][c].toString();//HERE IS THE CELL
    flexTableReg.setText(r+1, c, text);


  }
  var id = rowsToConfirm[r][0];
  check[r] = app.createCheckBox().setName("chk_"+id).setId("chk_"+id);
  flexTableReg.setWidget(r+1, lastCol, check[r]);
}//end fors
}//end if

 var botMod = app.createButton().setText("Activar").setId("botStatus");
 var botHandle =  app.createServerHandler("changeStatus").addCallbackElement(verticalPanelAdmin);
 botMod.addClickHandler(botHandle);

mainPanelAdmin.add(flexTableReg);
mainPanelAdmin.add(botMod);
verticalPanelAdmin.add(mainPanelAdmin);
absolutePanelAdmin.add(verticalPanelAdmin);
app.add(absolutePanelAdmin);

return app;
}

function changeStatus(e){
  var ss = SpreadsheetApp.openById(LOGS_SHEET_ID);
  var app = UiApp.getActiveApplication();
  var datarray = getDataArray();
  var lastRow = ss.getLastRow();

  for(var i =0; i<=lastRow;i++ ){
    try{
      var par =  e.parameter["chk_"+i];


      if(true){
        stop_if_true
        var row = getRowByID(0,lastRow,i);
         ss.getRange("E"+i).setValue("1");
      }//end if     
    }catch(e){e.parameter_"undefined"  //if e.parameter "undefined"
          return app;}
}//end for
 return app;
 }; 

解决方案

I don't know what var id = rowsToConfirm[r][0]; is returning, but that is what you're using as the original id parameter when setting the .setName() and .setId() properties.

When you try to get the values in the callback function you use a numeric i param so that could clash.

Second, the return value of a checkbox is always a string so check for 'true' or 'false' instead of true or false.

hope this helps,

Greets.

这篇关于当按下按钮时,我需要获得复选框的输入值(True / False)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆