-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I dont want use apply attribute with foreach Can it possible to use viewModel in place of apply
<zk xmlns:x="xhtml" xmlns:zk="zk"> <window border="normal" title="hello" apply="pkg$.TestComposer"> <div>Welcome to ZK Fiddle , run it right now!</div> <zscript> List list =new ArrayList(); list.add("1"); list.add("2"); List list1 =new ArrayList(); list1.add("3"); list1.add("4"); Map a = new HashMap(); a.put("key1", list); a.put("key2", list1); </zscript> <zk forEach="${a}"> <label value="${each.value}"/> <separator/> </zk> </window> </zk>
I think everything you need is at http://books.zkoss.org/wiki/ZK_Getting_Started/Get_ZK_Up_and_Running_with_MVVM...
I think i am not able to clear my issue i have to use same code only change will be i will want to use ViewModel with foreach because i am using Map so Model not able to iterate map
thanks
Can anyone know how can i resolve this issue
@Natividaddly What do you mean by resolved ? this question asked by me and still it is not resolved please dont post anything in any thread if it is not relates to you
thanks
@sjoshi...
//might be typos here.. but you get the idea...
public class YourViewModel { private List<Employee> employees; public List<Employee> getEmployee() { something.returnListofEmployees(); } } //ZUL <window title="Your Page" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('com.foo.YourViewModel"> <vlayout children="@load(vm.employees)"> <template name="children"> <label value="@load(each.name)"/> </template> </vlayout> </window>
Do you think children attribute will work with Map i am using foreach because i have a Map and forEach working Fine with Map
@Benbai did you update anything for my issue? I did not get any of your reply but forum showing you posted something.
Any one know how can i resolve this issue
@Sjoshi, 'm not trying to be a smart ass but I'm guessing your pretty new to Java? Have you looked at the Map API? http://docs.oracle.com/javase/6/docs/api/java/util/Map.html
A map has methods like "entrySet()" of "values()" so you can just expose those in your ViewModel depending on what you need.
If you just need the values of your map (as your example shows) just add this to your ViewModel:
public Collection<YourObject> getMyMapValues() { return myMap.values(); }
Then use it like any other Collection in your template.
Do you need the key and the value? If you do expose EntrySet...
public Set getMyMapEntrySet() { return myMap.entrySet(); }
To use the latter...
<listbox id="foo" model="@load(vm.myMapEntrySet)"..... <template name="model" var="item"> <listitem > <listcell label="@load(item.key)"></listcell> <listcell label="@load(item.value)"></listcell> </listitem> </template>
might be other ways to use the entrySet or values property of a map directly within the zul listbox, but considering it's only 3 lines of code to add to your ViewModel to do the above, I wouldn't sweat it.
Asked: 2012-11-09 10:09:52 +0800
Seen: 189 times
Last updated: Nov 19 '12