answered
2013-03-09 16:46:59 +0800
rickcr 704 ● 7 NOTE: why do comments only allow so few characters? I want to follow up to my original without actually answering the question, but because the comments only allow about 300 characters that's not much.
Anyway, how would one even create an onClick handler dynamically like that to be picked up in one's composer? I'm trying to be well-rounded in my ZK knowledge and I'd like to know how to do this 'without' using a VM?
So for example, I read you don't have "each" within a even listener so you have to create a custom attribute.. but how would you know how to get the attribute when the components are created dynamically? You can't really wire them up in your composer?
How could I get access to "each.code" in a click listener in my Composer? I can't really get the component by id since I the number of href components is dynamic...
<zk forEach="${reportsMenu$composer.reports}">
<a label="${each.name}" onClick="openReport">
<!-- I need this each.code value in Composer onClick ! -->
<custom-attributes myValue="${each.code}"/>
</a>
</zk>
Note I wanted to do ...
<zk forEach="${reportsMenu$composer.reports}">
<a label="${each.name}" onClick="openReport(${each.code}"/>
</zk>
EDIT 3/11
per @Dennis solution:
<a label="${each.name}" onClick="@command('onShowContent', page=myValue)">
<custom-attributes myValue="${each.code}"/>
</a>
The solution worked PERFECTLY for calling the outer VM, but I agree this is sort of messy.. sending of a global command from the composer would be better.
So that being said, How would you do this in the classic MVC approach? How do I notify an onClick in my composer when I can't give the onclick an id, since the links/button are created on-the-fly? Do I need to use a script in my onclick that sets a hidden variable and then fire off some sort of click event in the zscript for the composer to bind to?
For example the theory is I'd want to get a click handle in my composer to read
<zk forEach="${reportsMenu$composer.reports}">
<a label="${each.name}" onClick="openReport(myValue)">
<custom-attributes myValue="${each.code}"/>
</a>
</zk>
But I'd need an @Listen in my Composer that could listen for this, but I can't give it an id since it won't be unique. Javascript could get the openReport with the page value just fine, but now I have to still send that to the composer from javascript?