gpt4 book ai didi

java - Sencha GXT XTemplate tpl for inside tpl for

转载 作者:行者123 更新时间:2023-12-02 07:27:59 27 4
gpt4 key购买 nike

我正在尝试使用 GXT 3.0 的 XTemplates(类似于 EXT),这里有 2 个具有以下关系的简单 java 对象:

class A {
String name;
public String getName() {
return name;
}
}

class B {
String name;

public String getValue(A a) {
return a.getName();
}
}

我想为以下模板应用带有 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>

有熟悉此类请求的机构吗?谢谢。

最佳答案

有一个特殊的命名对象可以帮助您处理这个问题,称为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>

如果存在第三个循环,您可以将调用链接到父级以进一步退出 - parent.parent.name

如果 A 有 getPhone() 方法,但 B 没有,则 parent 是可选的,因为显然您不能引用非-存在b.getPhone()

this example中也使用了同样的原理。 ,其中打印了每个 child 以及 parent 的详细信息。查看 template.html 文件的源代码,了解在这种情况下如何使用 parent

关于java - Sencha GXT XTemplate tpl for inside tpl for,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13294443/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com