在小部件上使用标签 [英] Using TAGS on widgets

查看:64
本文介绍了在小部件上使用标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在UI小部件中使用标签,但标签值在处理函数中不可用(返回'null')。

是否应该像那样工作(在这种情况下,对我来说这是无用的)还是我做错了什么?如果有人对TAG有任何经验,我会很感激任何建议;)

以下是我用于测试的代码:

 函数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()); //这一行检查setTag / getTag是否正常工作,它应该在同一个函数中
app.add(panel。添加(LBL));
var CH = app.createServerHandler('showtag')。addCallbackElement(panel);
lbl.addClickHandler(CH)

返回应用;



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

可以测试 with this link



编辑:我在代码中添加了一行,它在doGet函数中读写标记,只是为了测试...

编辑2 :由Srik提供的解决方案,就像这样简单:

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


解决方案

好。这里有个小怪癖。在您的处理程序中,您可以通过以下方法访问标记值:

$ p $函数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 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
}

解决方案

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 */
  ....
}

这篇关于在小部件上使用标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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