开发者

ZK CDATA and passing a variable?

开发者 https://www.devze.com 2023-01-28 05:01 出处:网络
I have been struggling with this for a couple of days now and I can\'t seem to get it right. Here is my code:

I have been struggling with this for a couple of days now and I can't seem to get it right. Here is my code:

<attribute name="onClick"><![CDATA[
Messagebox.show("Remove this file?", "Remove?", Messagebox.YES | Messagebox.NO, Messagebox.QUESTION,
new EventListener() {
    public void onEvent(Event evt) {
        switch (((开发者_如何转开发Integer)evt.getData()).intValue()) {
            case Messagebox.YES: someFunction(${each.Id}); break;
            case Messagebox.NO: break;
        }
    }
})
]]></attribute>

The above code is from a forEach cycle in a ZK ZUL page. It should generate a list of files and on every file you should have a "Delete" button. When you click on it a popup should come up and ask for confirmation. After you confirm it should pass the id to a function which from then handles everything.

I'm quite sure it's something really small I'm missing or not knowing.


There are two issues here.

  1. You cannot use EL in zscript. Rather, you have to access it through implicit object. For example,
    <window>
      <button label="${each}" forEach="apple, orange">
        <zscript>
      self.parent.appendChild(new Label("" + each));
        </zscript>
      </button>
    </window>
  1. However, each is available only in the page rendering. It is reset after evaluated. It means, you can't access it in the event listener. For example, the following won't work
    <window>
      <button label="${each}" forEach="apple, orange"
        onClick='alert(""+each)'/> 
    </window>

You have to store the each object first and then use it in the event listener.

You might take a look at ZK's reference

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号