如何设置语言环境类和 UI 组件之间的绑定
我试图弄清楚如何正确设置 Locale 类和 mxml 文件之间的绑定。
我的主 mxml 文件包含:
<mx:Button id="TMP" label="{Locale.getLocaleString('title'}"/>
我想在按钮的标签中显示一个空字符串,直到加载区域设置文件。加载语言环境文件后,我想显示 getLocaleString('title') 返回的内容。
我认为这就是绑定的目的,但我认为我的做法是错误的。
我知道我不允许绑定函数。那么我是否需要允许访问(使用 get 函数)我的 _dictionary
属性?为这样的事情设置绑定的标准方法是什么?
这是我当前的 Locale 类。
public class Locale {
private static var _dictionary:Dictionary = new Dictionary();
public static function loadResources():void {...}
public static function getLocaleString(featureID:String):String {
if(_dictionary[featureID]==null){
return "";
}
return _dictionary[featureID];
}
}
I am trying to figure out how to properly setup binding between my Locale class and an mxml file.
My main mxml file contains:
<mx:Button id="TMP" label="{Locale.getLocaleString('title'}"/>
I would like to display an empty string in the button's label until the locale file loads. Once the locale file loads I would like to display what is returned by getLocaleString('title')
.
I think that this is what Binding is intended for however I think that I am approaching it wrong.
I know that I am not allowed to bind on a function. So do I need to allow access (using a get function) to my _dictionary
property? What is the standard way to setup Binding for something like this?
This is my current Locale
class.
public class Locale {
private static var _dictionary:Dictionary = new Dictionary();
public static function loadResources():void {...}
public static function getLocaleString(featureID:String):String {
if(_dictionary[featureID]==null){
return "";
}
return _dictionary[featureID];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我找到的解决方案:
EventDispatcher
,使类可绑定并在加载完成时调度一个事件。 (doc)这是我的最终代码:
This is the solution I found:
EventDispatcher
, make the class Bindable and dispatch an event when loading has completed. (doc)Here is my final code: