Flex:ButtonBarButton中的附加标签 [英] Flex: Additional label in ButtonBarButton

查看:147
本文介绍了Flex:ButtonBarButton中的附加标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试扩展ButtonBarButton以包含一个附加标签,显示viewstack中相应框的更新数(这是tabbar的dataProvider)。

I'm trying to extend ButtonBarButton to include an additional label that shows the number of updates for the respective box in a viewstack (which is the tabbar's dataProvider).

我可以从数据中获取附加标签(名为indicatorLabel)来读取初始值,但是我无法像实际的label属性那样自动更新。我的理解是你可以绑定到数据对象,但这似乎不是这样的。

I can get the additional label (named indicatorLabel) to read an initial value from data, but I can't get it to update automatically like the actual "label" attribute. My understanding was that you could bind to the data object, but that doesn't appear to be the case.

在viewstack中使用的框具有称为_indicator

The box that is used in the viewstack has an attribute called _indicator


[Bindable]
public var _indicator:String;

我知道更新正确,因为我可以在框中看到它更新(也有一个标签绑定它)。它似乎只是不更新​​按钮栏。

Which I know is updating properly because I can see it updating in the box (which also has a label bound to it). It appears to just not update the buttonbarbutton.

我的buttonbarbutton类有以下(其中init()在creationComplete中调用

My buttonbarbutton class has the following (where init() is called in creationComplete


[SkinPart]
public var indicatorLabel:spark.components.Label;

private function init():void
{
 indicatorLabel = data._indicator;
 addEventListener("dataChange", onDataChangeHandler);
}

private function onDataChangeHandler(e:Event):void
{
 trace(e.target.label + ' ' + e.target._indicator);
}

我猜测我的数据绑定或被传递到按钮的数据obj的假设是不正确的,任何帮助都不胜感激。

I'm guessing my assumptions for either databinding or the data obj that gets passed to the button are incorrect. Any help is appreciated.

推荐答案

几天前我已经回答了一个与这个密切相关的问题,这有点更抽象,但也应该回答你, a href =http://stackoverflow.com/questions/8353777/flex-communic在皮肤和数据模型之间进行沟通?

I have answered a question here just a few days ago that is closely related to this one. It's a bit more abstract, but it should answer yours too. Have a look at Flex : Communicate between the skin and the data model?

关于性能改进的其他问题:您只需要记住,无论何时使用绑定,编译器将生成一些事件侦听器来监听数据的更改。当然,这不是一次性组件的问题,甚至是一堆实例,但如果您有一个列表,其中包含数千个组件,这些组件都使用绑定,那么它可能会成为一个问题。首先,垃圾收集器不会在不再需要时轻松清理这些组件,其次 - 根据您的实施情况 - 数千个事件可能会一次触发。

As for your additional question about performance improvement: you just have to keep in mind that whenever you use binding, the compiler will generate some event listeners to listen for changes in the data. Of course that's not an issue with a one-off component or even with a bunch of instances, but it may become one if you have a List with thousands of components that all use binding. First of all the garbage collector won't clean these components up so easily when they're no longer needed and secondly - depending on your implementation - thousands of events may be firing at once.

底线:您可以考虑 commitProperties()方法性能调整,因此您不应考虑一下,直到你真的遇到一个性能问题。

bottom line: you could consider the commitProperties() approach performance tuning, hence you shouldn't consider it until you actually run into a performance issue.

另一方面从架构的角度来看:这种方法允许一个<强>清洁分离组分及其皮肤。使用 hostComponent / 绑定方法可以说皮肤知道太多:它必须了解其主机组件和其属性。而另一个让你有一个完全哑的皮肤。所以再次,我倾向于使用一次性组件和 commitProperties()与高度可重用的绑定。

on the other hand from an architectural point of view: that approach allows for a cleaner separation of the component and its skin. With the hostComponent / binding approach you could say the skin knows too much: it has to know about its host component and its properties. While the other one allows you to have a completely 'dumb' skin. So again I tend to use binding with one-off components and commitProperties() with highly reusable ones.

最终这一切都是一个权衡(因为干净的方式更复杂和更多的工作),由你决定为每个特定情况作出权衡。

In the end it's all a trade-off (because the 'clean' way is more complex and more work) and it's up to you to make a weighed decision for each particular situation.

这篇关于Flex:ButtonBarButton中的附加标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆