Reputation: 27
I'm trying to use XTemplates of GXT 3.0 (similar as EXT) and here are 2 simple java objects that have below relationship:
class A {
String name;
public String getName() {
return name;
}
}
class B {
String name;
public String getValue(A a) {
return a.getName();
}
}
I want to apply XTemplate with 2 arguments (List<< A>> aList, List<< B>> bList) for following template:
<tpl for="aList">
<tpl for="bList">
////// Questions? How to call function B.getValue(A) ???
///// this does not work for me: {this.getValue(parent)}
</tpl>
</tpl>
Have any body familiar with such kind request? Thanks.
Upvotes: 0
Views: 1111
Reputation: 18346
There is a special named object to help you deal with this called parent
- this accesses the external scope.
<tpl for="aList">
<tpl for="bList">
Name of inner item, i.e. b.getName() is {name} <br />
Name of outer item, i.e. a.getName() is {parent.name}
</tpl>
</tpl>
If there was a third loop, you could chain the calls to parent to get out further - parent.parent.name
.
And if A had a getPhone()
method, but B didn't, then the parent
is optional, since clearly you can't be referring to the non-existent b.getPhone()
.
This same principle is used in this example, where the each child has their details printed, along with the parent's. Take a look at the source of the template.html
file to see how parent
is used in that case.
Upvotes: 2