将模型传递到其他组件

时间:2013-01-16 21:03:47

标签: actionscript-3 flex

我正在调试一个问题,即模型中的ArrayCollection没有在UI中更新(即使我在新数据中看到它)。

我想知道是否将该模型传递到其他组件(即顶级组件)会导致问题。

例如,这是我在顶级的模型:

[Bindable]
        private var meetingInfo:MeetingInfoModel;

现在我将它传递给同一个类中的一个组件:

<meetingViewStack:MeetingViewStack id="mainPanelContainer"
                                   newAttachmentsList="{meetingInfo.newAttachmentList}"
                                   meetingInfo="{meetingInfo}"
                                   currentState="{getPanelState(currentState)}"
                                   inCreateMeeting="false" 
                                   includeIn="runSinglePanel, runDoublePanel"
                                   height="100%"
                                   width="100%"
                                   />

以下是我在MeetingViewStack组件中声明的属性:

[Bindable] 
        public var meetingInfo:MeetingInfoModel = MeetingInfoModel.getInstance();

绑定在MeetingViewStack中是否正常工作?即使该属性已被另一个组件传递给它。

我的意思是我真的没有迫切需要传递它。这是一个模型,我可以在那里声明它。

感谢您提供任何有用的提示!

更新:

我已经验证在更新meetingInfo属性时会调用setter。但是,当我更新meetingInfo模型中的数组集合时,它不会被调用,即

meetingInfo.docsAndAttachmentsList.sort = nameSort;
        meetingInfo.docsAndAttachmentsList.refresh();

我怎样才能让它发挥作用?这就是我真正想要的。

这是MeetingInfoModel类:

package com.fmr.transporter.model

{     import com.fmr.transporter.events.CustomEvent;     import com.fmr.transporter.events.xmppServicesEvents.XMPPContactsLoadedEvent;     import com.fmr.transporter.services.httpservices.UserServices;     import com.fmr.transporter.services.xmppservices.XMPPServices;     import com.fmr.transporter.util.util;     import com.fmr.transporter.vo.ContactVO;     import com.fmr.transporter.vo.MeetingVO;     import com.fmr.transporter.vo.ParticipantVO;

import flash.events.EventDispatcher;

import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;

import org.igniterealtime.xiff.data.im.RosterItemVO;

[Bindable]
public final class MeetingInfoModel extends EventDispatcher
{
    //Universal INFO
    public var generalInfo:GeneralInfoModel;
    public var meetingVO:MeetingVO = new MeetingVO();
    public var meetingId:String;

    public var bulletinBoardLiveMembers:ArrayCollection = new ArrayCollection();

    public var xmppServices:XMPPServices;

    public var declinedParticipantsGroup:ArrayCollection = new ArrayCollection();
    public var notJoinedParticipantsGroup:ArrayCollection = new ArrayCollection();
    public var conferenceRoomParticipantsGroup:ArrayCollection = new ArrayCollection();
    public var otherLocationParticipantsGroup:ArrayCollection = new ArrayCollection();

    public var documentList:ArrayCollection = new ArrayCollection();

    public var newAttachmentList:ArrayCollection = new ArrayCollection();
    public var docsAndAttachmentsList:ArrayCollection = new ArrayCollection();

    public var bulletinBoardMsgList:ArrayCollection = new ArrayCollection();

    private var _participantList:ArrayCollection = new ArrayCollection();
    public var dismissedMeetingIDs:Array = [];
    public var visibleToastWindows:Array = [];

    public function MeetingInfoModel()
    {
        generalInfo = GeneralInfoModel.getInstance();
        xmppServices = XMPPServices.getInstance();
        _participantList.addEventListener(CollectionEvent.COLLECTION_CHANGE, allParticipantsChangeHandler);
        bulletinBoardLiveMembers.addEventListener(CollectionEvent.COLLECTION_CHANGE, bulletinBoardLiveMembersChangeHandler);
    }

    private static var model:MeetingInfoModel = null;

    public static function getInstance():MeetingInfoModel
    {
        if (model == null)
        {
            model = new MeetingInfoModel();
        }
        return model;
    }

    public function displayToastForThisMeeting(meetingID:Number):Boolean
    {
        //trace("model::meetingID = " + meetingID);
        var doDisplayToast:Boolean = false;
        var containsMeetingID:Boolean = false;
        //the first one
        if(dismissedMeetingIDs.length == 0)
        {
            //trace("dismissedMeetingIDs.length = 0");
            doDisplayToast = true;
            dismissedMeetingIDs.push(meetingID);
        }
        else
        {
            for(var i:int=0; i < dismissedMeetingIDs.length; i++)
            {
                //trace("dismissedMeetingIDs[" + i + "] = " + dismissedMeetingIDs[i]);
                if(meetingID == dismissedMeetingIDs[i])
                {   //this one has already been dismissed
                    doDisplayToast = false;
                    containsMeetingID = true;
                    break;
                }
                else
                {
                    doDisplayToast = true;
                    containsMeetingID = false;
                }
            }

            if(containsMeetingID == false)
            {
                dismissedMeetingIDs.push(meetingID);
            }
        }
        return doDisplayToast;
    }

    public function setAllParticipants(value:ArrayCollection):void
    {
        _participantList = value;
        dispatchEvent(new CustomEvent(CustomEvent.HAVE_PARTICIPANT_LIST));
        calculateGroups();
    }

    public function getParticipant(loginName:String):ParticipantVO
    {   
        for each (var item:ParticipantVO in _participantList)
        {
            if (item.loginName == loginName)
            {
                return item;
            }
        }
        return null;    
    }

    private function allParticipantsChangeHandler(event:CollectionEvent):void
    {
        calculateGroups();
    }

    private function bulletinBoardLiveMembersChangeHandler(event:CollectionEvent):void
    {
        calculateGroups();
    }

    private function isInRoster( loginName:String ):Boolean { 
        for each (var newContactVO:ContactVO in model.generalInfo.allGroup)
        {
            if ( newContactVO.profileVO.email == loginName ) {
                return true;
            }
        }
        return false;
    }

    public function calculateGroups():void
    {
        var allGroup:ArrayCollection = generalInfo.allGroup;

        var participantsRosterGroup:ArrayCollection = new ArrayCollection();
        var declinedParticipantsGroup:ArrayCollection = new ArrayCollection();
        var notJoinedParticipantsGroup:ArrayCollection = new ArrayCollection();
        var conferenceRoomParticipantsGroup:ArrayCollection = new ArrayCollection();
        var otherLocationParticipantsGroup:ArrayCollection = new ArrayCollection();

        var notDeclinedParticipantsGroup:ArrayCollection = new ArrayCollection();

        for each (var item:Object in _participantList)
        {
            //because participant list contains both people and rooms, we must test to see if this is a participant
            if(item is ParticipantVO)
            {
                var xmppLoginName:String = util.formatEmailToUserName(item.loginName);
                for each (var newContactVO:ContactVO in allGroup)
                {

                    if ( item.loginName != model.generalInfo.ownerUser.loginName ) {
                        var rosterVO:RosterItemVO = newContactVO.rosterItemVO;

                        if (rosterVO.jid.node == xmppLoginName)
                        {
                            try {
                                var contactVO:ContactVO = new ContactVO();
                                //add the photo to the roster entry for each person in the meeting
                                if ( newContactVO.profileVO ) {
                                    rosterVO.photo = newContactVO.profileVO.photo;
                                    contactVO.profileVO = xmppServices.findProfile(rosterVO.jid);
                                    contactVO.profileVO = newContactVO.profileVO;
                                }
                                else {
                                    rosterVO.photo = null;
                                }

                                contactVO.rosterItemVO = rosterVO;

                            }
                            catch (e:Error) {
                                trace(e.message);
                            }

                            if (item.status == "declined")
                            {
                                declinedParticipantsGroup.addItem(contactVO);
                            }
                            else
                            {
                                notDeclinedParticipantsGroup.addItem(contactVO);
                            }
                            break;
                        }
                    }
                }
            }



        }

        for each (var contact:ContactVO in notDeclinedParticipantsGroup)
        {
            var joined:Boolean = false;
            if ( contact.rosterItemVO ) {
                for each (var memberName:String in bulletinBoardLiveMembers)
                {
                    if (contact.rosterItemVO.jid.node == memberName)
                    {
                        joined = true;

                        if (contact.rosterItemVO.jid.resource == "theconfroomimsittingin"  )
                        {
                            conferenceRoomParticipantsGroup.addItem(contact);
                        }
                        else
                        {
                            otherLocationParticipantsGroup.addItem(contact);
                        }
                        //dispatchEvent "DW has joined the meeting"
                        break;
                    }
                }
            }

            if (!joined)
            {
                notJoinedParticipantsGroup.addItem(contact);
            }
        }

        this.notJoinedParticipantsGroup = notJoinedParticipantsGroup;
        this.declinedParticipantsGroup = declinedParticipantsGroup;
        this.otherLocationParticipantsGroup = otherLocationParticipantsGroup;
        this.conferenceRoomParticipantsGroup = conferenceRoomParticipantsGroup;
    }

    public function clearMeeting():void
    {
        meetingId = "";
        _participantList.removeAll();
        docsAndAttachmentsList.removeAll();
        documentList.removeAll();
        newAttachmentList.removeAll();
        bulletinBoardMsgList.removeAll();
        bulletinBoardLiveMembers.removeAll();
    }
    [Bindable]
    public function get participantList():ArrayCollection
    {
        return _participantList;
    }

}

}

1 个答案:

答案 0 :(得分:2)

认为你的绑定方式错误。

在顶层应该是:

[Bindable] private var meetingInfo:MeetingInfoModel = MeetingInfoModel.getInstance();

在MeetingViewStack组件中:

[Bindable] public var meetingInfo:MeetingInfoModel;

它还可能取决于MeetingInfoModel类中的哪些属性是[Bindable]。