如果 gxt 模板中的字符是中文,请检查 tpl-if-tag
Check in a tpl-if-tag, if characters are chinese in a gxt template
在我的 java gxt-project 中,我有一个模板,其中有以下 tpl 标签,这些标签根据父标题决定标题是否必须为斜体。
<tpl if="titleORG != """>
<tpl if="ParentTitleORG == """><i></tpl>
<b>{titleORG}<tpl if="subtitleORG != """>: {subtitleORG}</tpl></b>
<tpl if="ParentTitleORG == """></i></tpl>
</tpl>
<tpl if="titleEN != """>
<tpl if="officialTitleTranslation"> / {titleEN}<tpl if="subtitleEN != """>: {subtitleEN}</tpl></tpl>
</tpl>.
最近收到工单,如果不是中文或韩文,是否可以只将标题设为斜体
知道吗,我该如何检查?
谢谢,
埃里克
您必须在传递给 XTemplate 的 Class 中进行检查。
添加一个布尔值(我将其称为 ckj)并在您的构造函数中进行设置。 [使用 GXT 文档中的 Person 示例]
public class Person {
private String name;
private boolean ckj;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
this.ckj=containsJapanese(name);
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public boolean containsCKJ(String s) {
return s.codePoints()
.anyMatch(codepoint -> (Character.UnicodeScript.of(codepoint) == Character.UnicodeScript.HAN
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_C
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_D
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_COMPATIBILITY
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_STROKES
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.ENCLOSED_IDEOGRAPHIC_SUPPLEMENT
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.KANGXI_RADICALS
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS
));
}
}
然后您可以在模板中使用 if 表达式。
<tpl if="!ckj">
//italics
<tpl if="ckj">
//no italics
这里有更多关于检查 CKJ 字符的讨论
在我的 java gxt-project 中,我有一个模板,其中有以下 tpl 标签,这些标签根据父标题决定标题是否必须为斜体。
<tpl if="titleORG != """>
<tpl if="ParentTitleORG == """><i></tpl>
<b>{titleORG}<tpl if="subtitleORG != """>: {subtitleORG}</tpl></b>
<tpl if="ParentTitleORG == """></i></tpl>
</tpl>
<tpl if="titleEN != """>
<tpl if="officialTitleTranslation"> / {titleEN}<tpl if="subtitleEN != """>: {subtitleEN}</tpl></tpl>
</tpl>.
最近收到工单,如果不是中文或韩文,是否可以只将标题设为斜体
知道吗,我该如何检查?
谢谢,
埃里克
您必须在传递给 XTemplate 的 Class 中进行检查。
添加一个布尔值(我将其称为 ckj)并在您的构造函数中进行设置。 [使用 GXT 文档中的 Person 示例]
public class Person {
private String name;
private boolean ckj;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
this.ckj=containsJapanese(name);
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public boolean containsCKJ(String s) {
return s.codePoints()
.anyMatch(codepoint -> (Character.UnicodeScript.of(codepoint) == Character.UnicodeScript.HAN
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_C
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_D
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_COMPATIBILITY
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_STROKES
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.ENCLOSED_IDEOGRAPHIC_SUPPLEMENT
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.KANGXI_RADICALS
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS
));
}
}
然后您可以在模板中使用 if 表达式。
<tpl if="!ckj">
//italics
<tpl if="ckj">
//no italics
这里有更多关于检查 CKJ 字符的讨论