0

How do you use a VM property in a zk element?

asked 2012-02-22 18:40:43 +0800

emersonf gravatar image emersonf
39

I'm trying to show a particular piece of ZUL if my view model has a variable.

<zk switch="@load(vm.foo)">

and

<zk if="@load(not empty vm.foo)">

don't resolve vm.foo. Is there some other way to include fragments conditionally based on properties in my VM?

Thanks,
Emerson

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2012-02-27 09:44:49 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

Hi Emerson,

For dynamic display a particular piece of ZUL, try this:

<!-- the label is visible if vm.showFragment is not empty -->
<label value="the fragment" visible="@load(not empty vm.showFragment)" />

<!-- include src is vm.fragmentSrc, will show nothing if it is null or not exists  -->
<include src="@load(vm.fragmentSrc)" />

Regards,
ben

link publish delete flag offensive edit

answered 2012-02-27 11:14:48 +0800

emersonf gravatar image emersonf
39

Thanks Ben. I've ended up using the visible attribute on macros, basically the first option you suggested but on macros. Something like...

<fragmentMacro visible="@load(not empty foo)"/>

The problem with the second "include" option is that I think it breaks the MVVM pattern. The ViewModel shouldn't know what the fragment source is, since the VM is meant to be independent from the view.

The macro option seems to work, especially with fulfill= to only create the fragment components on certain events. Now if only there were a way to destroy the fragment when the condition changes...

link publish delete flag offensive edit

answered 2015-06-08 13:36:24 +0800

WilliamB gravatar image WilliamB
1609 1 6

Does <zk switch="@load(vm.foo)"> even work? Tried and didn't seems the switch was updating when the vm.foo value changed.

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2012-02-22 18:40:43 +0800

Seen: 260 times

Last updated: Jun 08 '15

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