Data binding 如何绑定到ArrayCollection中的第一项?

Data binding 如何绑定到ArrayCollection中的第一项?,data-binding,flex3,Data Binding,Flex3,我的应用程序使用MVC模型。该模型包含一个可绑定类(BindableItemsClass),该类包含一个ArrayCollection。我想将视图中的一些内容绑定到可绑定类的ArrayCollection中的第一项(因此属性“firstItem”) 问题在于,当使用setter“set firstItem(value:Object)”时,绑定到该属性的视图组件不会更新 是否有方法手动触发属性“firstItem”的绑定 [Bindable] public class BindableItemsC

我的应用程序使用MVC模型。该模型包含一个可绑定类(BindableItemsClass),该类包含一个ArrayCollection。我想将视图中的一些内容绑定到可绑定类的ArrayCollection中的第一项(因此属性“firstItem”)

问题在于,当使用setter“set firstItem(value:Object)”时,绑定到该属性的视图组件不会更新

是否有方法手动触发属性“firstItem”的绑定

[Bindable]
public class BindableItemsClass extends EventDispatcher
{
    private var _items:ArrayCollection;

    public function get items():ArrayCollection
    {
        return _items;
    }

    public function set items(value:ArrayCollection):void
    {
        _items = value;
    }

    public function get firstItem():Object
    {
        if(_items && items.length>0)
            return items[0];
        else
            return null;
    }

    public function set firstItem(value:Object):void
    {
        if(value)
            items = new ArrayCollection([value]);
        else
            items = new ArrayCollection();
    }
}

分派更改事件以触发setter中的绑定:

dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
这应该行得通

如果没有,那么您可能还需要为getter添加注释:

[Bindable("dataChange")]
public function get firstItem():Object
{
    if(_items && items.length>0)
        return items[0];
    else
        return null;
}
这显式地定义了一个函数的绑定侦听器,因此监视该函数的属性将了解要侦听的事件