首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将模型传递给其他组件

将模型传递给其他组件
EN

Stack Overflow用户
提问于 2013-01-17 05:03:47
回答 1查看 70关注 0票数 0

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

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

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

代码语言:javascript
复制
[Bindable]
        private var meetingInfo:MeetingInfoModel;

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

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

下面是我如何在MeetingViewStack组件中声明该属性:

代码语言:javascript
复制
[Bindable] 
        public var meetingInfo:MeetingInfoModel = MeetingInfoModel.getInstance();

绑定应该在MeetingViewStack中正常工作吗?即使该属性是由另一个组件传递给它的。

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

感谢你的任何有用的提示!

更新:

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

代码语言:javascript
复制
meetingInfo.docsAndAttachmentsList.sort = nameSort;
        meetingInfo.docsAndAttachmentsList.refresh();

我怎么才能让它工作呢?这才是我真正要找的。

下面是MeetingInfoModel类:

代码语言:javascript
复制
package com.fmr.transporter.model

{ 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;

代码语言:javascript
复制
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;
    }

}

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-17 08:15:23

我想你把绑定弄错了。

在顶层,它应该是:

代码语言:javascript
复制
[Bindable] private var meetingInfo:MeetingInfoModel = MeetingInfoModel.getInstance();

在MeetingViewStack组件内部:

代码语言:javascript
复制
[Bindable] public var meetingInfo:MeetingInfoModel;

它还可能取决于MeetingInfoModel类中的哪些属性是可绑定的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14367789

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档