-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
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
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...
Asked: 2012-02-22 18:40:43 +0800
Seen: 260 times
Last updated: Jun 08 '15