Using TAGS on widgets

2019-09-06 03:51发布

问题:

I'm trying to use tags in UI widgets but the tag value is not available in the handler function (returns 'null').

Is it supposed to work like that (in this case it's kind of useless for me) or am I doing something wrong ? if anyone has any experience with TAGS, I'd appreciate any advice ;-)

Here is the code I used for testing :

function doGet(e) {
  var app = UiApp.createApplication();
  var panel = app.createVerticalPanel();
  var lbl = app.createTextBox().setWidth('400').setId('lbl');
  lbl.setText('empty').setTag('tag value');
  lbl.setText('original value = '+lbl.getTag());// this line to check that setTag / getTag is working as it should in the same function
  app.add(panel.add(lbl));
  var CH = app.createServerHandler('showtag').addCallbackElement(panel);
  lbl.addClickHandler(CH)

  return app;
}


function showtag(){
var app = UiApp.getActiveApplication();
var lbl = app.getElementById('lbl')
lbl.setText('new value = '+lbl.getTag());
return app
}

It can be tested with this link

EDIT : I added a line in the code that reads and writes the tag in the doGet function, just to test ...

EDIT 2 : the solution by Srik, as simple as that :

function showtag(e){
var app = UiApp.getActiveApplication();
var lbl = app.getElementById('lbl')
lbl.setText('from showtag value = '+e.parameter.lbl_tag);
return app
}

回答1:

OK. There is a small quirk here. IN your handler, you can access the tag value in the following method

function doGet(){
   ....
   var lbl = app.createTextBox().setWidth('400').setId('lbl');
   lbl.setText('empty').setTag('tag value');
   ....
}

function showtag(e){
  var tag = e.parameter.lbl_tag; /* I'm not sure if it us Tag or tag */
  ....
}