I need to get the input value (True/False) of a ch

2019-09-16 10:45发布

问题:

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;
 }; 

回答1:

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.