我正在调试模型上的 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
{ 进口 com.fmr.transporter.events.CustomEvent; 导入 com.fmr.transporter.events.xmppServicesEvents.XMPPContactsLoadedEvent;导入 com.fmr.transporter.services.httpservices.UserServices;导入 com.fmr.transporter.services.xmppservices.XMPPServices;导入 com.fmr.transporter.util.util;导入 com.fmr.transporter.vo.ContactVO;导入 com.fmr.transporter.vo.MeetingVO;导入 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;
}
}
}