我正在調試模型上的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();
應在Meetin正確結合工作gViewStack?即使該財產是由另一個組件傳入的。
我的意思是我真的沒有一個令人信服的需求來傳遞它。這是一個模型,我可以在那裏聲明它。
感謝您的任何有用的提示!
UPDATE:
我已經證實,當我更新了meetingInfo屬性的setter被調用。但是,它不會被調用,當我更新的meetingInfo模型中的數組集合,即
meetingInfo.docsAndAttachmentsList.sort = nameSort;
meetingInfo.docsAndAttachmentsList.refresh();
我怎麼能得到那個工作?這就是我真正想要的。
這裏的MeetingInfoModel類:
package com.fmr.transporter.model
{ 進口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;
}
}
}
是MeetinginfoModel.getInstance()的單身?如果是這樣,你就不必傳遞它,只是將它用作單例。否則,在任何情況下都以相同的方式訪問它。 – Gone3d
是的,綁定可以在你的MeetingViewStack中工作。你可以做的是在viewstack中添加一個setter(使meeingInfo爲private),然後看看setter是否被調用。 –
這是一個Singleton,是的。我只是覺得把它傳遞過去很奇怪,就這些。 – fumeng