fumeng
fumeng

Reputation: 1830

Update Label text field

I use a Label component to display the length of an ArrayCollection. How do I get it to update when I add new items to the collection?

Here's the text field for the Label:

text="{model.meetingInfo.documentList.length}"

Here's the handler for adding a new item to the collection:

var attachmentProgressVO:AttachmentProgressVO = new AttachmentProgressVO();
                attachmentProgressVO.fileReference = file as File;
                newAttachmentList.addItem(attachmentProgressVO);
                checkIfUpdate(file as File, attachmentProgressVO);
                meetingInfo.docsAndAttachmentsList.addItem(attachmentProgressVO);

I tried adding these 2 lines but that didn't work:

meetingInfo.docsAndAttachmentsList.itemUpdated( attachmentProgressVO );
                meetingInfo.docsAndAttachmentsList.refresh();

I also tried changing this:

public var docsAndAttachmentsList:ArrayCollection = new ArrayCollection();

to this:

private var _docsAndAttachmentsList:ArrayCollection = new ArrayCollection();

..with a getter and setter but that didn't work.

I'm not using the right approach, am I?

Upvotes: 0

Views: 335

Answers (1)

JeffryHouser
JeffryHouser

Reputation: 39408

Generically, Binding only looks at a specific object; you can't drill down 4 objects deep to a specific property and expect binding to update values.

Changing the documentList does not change meetingInfo or Model, so binding will never be triggered. itemUpdated() and refresh() should update the list based class which displays the data; but will not affect your label displaying the count.

You need to listen on the collection for a collectionChange event and manually update the label's text in the collectionChange handler.

Upvotes: 1

Related Questions