这个问题最好用一个例子来描述。
我的 GWT 应用程序中有以下 ClientBundle:
interface Resources extends ClientBundle {
public static final Resources INSTANCE = GWT.create(Resources.class);
@Source("defines.css")
Defines defines();
@Source("appStyle.css")
@CssResource.NotStrict
Style style();
interface Style extends CssResource {
String appLogo();
(...)
}
interface Defines extends CssResource {
String formInputBackgroundColor();
String formInputBorderColor();
(...)
}
}
appStyle.css
是应用程序使用的主要样式表,defines.css
是一个仅包含如下常量的样式表:
@def formInputBackgroundColor #D8ECFD;
@def formInputBorderColor #7FAAFF;
(...)
现在我可以使用 defines.css
中的常量了UIBinder 模板和应用程序代码中的样式表没有问题,但我不能在我的 appStyle.css
中使用这些常量.
我已经尝试替换 interface Style extends CssResource
与 interface Style extends Defines
, 希望继承自 Defines
样式表将使我能够访问“子”Style
中的常量样式表,但随后 GWT 编译器会报错,例如:
Rebinding my.project.client.resources.Resources
Creating assignment for style()
Replacing CSS class names
The following obfuscated style classes were missing from the source CSS file:
formInputBorderColor: Fix by adding .formInputBorderColor{}
formInputBackgroundColor: Fix by adding .formInputBackgroundColor{}
(...)
有什么办法可以实现吗?
最佳答案
我找到了一种方法来做到这一点,但它远非优雅,我更喜欢另一种解决方案,比如尽可能使用某种继承或注释。
我让它工作的方法是 @eval
appStyle.css
样式表中的 defines.css
我需要的每个常量,但这会导致大量代码重复,而且维护起来很麻烦。
@eval formInputBackgroundColor Resources.INSTANCE.defines().formInputBackgroundColor();
@eval formInputBorderColor Resources.INSTANCE.defines().formInputBorderColor();
如果您有更好的解决方案,请分享。
关于css - GWT:如何在同一个 ClientBundle 的另一个样式表中访问一个样式表中定义的常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3199880/