0

How do you reference a zul component with an iterative id, like id="popup_${each.id}"

asked 2016-05-02 19:09:57 +0800

djr gravatar image djr
1

I'm creating a popup for each line in a grid using the method described here:

www.zkoss.org/zkdemo/gettingstarted/dialogpopup

Where each row of a grid has a popup that is uniquely identified using Iterative Evaluation.

www.zkoss.org/wiki/ZK%20Developer's%20Reference/UI%20Composing/ZUML/Iterative%20Evaluation

The one thing that is not shown in this example is how to reference a component that has an id that's defined iteratively.

For example you can do this close a standalone popup from within the popup:

<popup id="testpopup">
    <button label="Close" onClick="testpopup.close()"/>
</popup>

But this doesn't work to close a popup from within the popup when the id is generated iteratively:

<grid ...>
...
<template name="model">
    <row popup="popup_${each.id}">
        ...
        <popup id="popup_${each.id}">
            <button label="Close" onClick="popup_${each.id}.close()"/>
        </popup>
    </row>
</template>
</grid>

Is there a notation that allows this reference "popup_${each.id}.close()" to work?

Thanks,

Derek

delete flag offensive retag edit

Comments

self.parent.close()

chillworld ( 2016-05-03 04:14:39 +0800 )edit

@chillworld I understand this resolves this simplified example, unfortunately it does not answer the question on how to reference a dynamically generated id. Thanks.

djr ( 2016-05-03 14:32:09 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-05-12 07:25:08 +0800

cor3000 gravatar image cor3000
4596 2 7
ZK Team

I created a zkfiddle example showing a few alternatives. Here the related documentation: component.getFellow(...), component.query(...), <custom-attributes>

In my opinion in most cases you don't need to know a dynamic id, as there's often a better way to implement such a requirement than using inline zscripts directly referencing dynamically created components.

If you can share the reasons behind your question there might be a more elegant solution. e.g. using [event-forwarding] and handle the close in a composer in java code. (https://www.zkoss.org/wiki/ZKDeveloper'sReference/EventHandling/EventForwarding)

Another example using no dynamic IDs at all http://zkfiddle.org/sample/231d3fg/3-find-component-without-id

Robert

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2016-05-02 19:09:57 +0800

Seen: 35 times

Last updated: May 12 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More