简体   繁体   English

Sencha GXT XTemplate tpl for inside tpl for

[英]Sencha GXT XTemplate tpl for inside tpl for

I'm trying to use XTemplates of GXT 3.0 (similar as EXT) and here are 2 simple java objects that have below relationship: 我正在尝试使用GXT 3.0的XTemplates(类似于EXT),这里有两个简单的java对象具有以下关系:

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: 我想为以下模板应用带有2个参数的XTemplate(List << A >> aList,List << B >> bList):

<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. 谢谢。

There is a special named object to help you deal with this called parent - this accesses the external scope. 有一个特殊的命名对象可以帮助您处理这个被称为parent - 这会访问外部作用域。

<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 . 如果有第三个循环,您可以将调用链接到父进一步 - 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() . 如果A有一个getPhone()方法,但B没有,那么parent是可选的,因为很明显你不能指不存在的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. 看一下template.html文件的来源,看看在这种情况下如何使用parent文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM