Expand my Community achievements bar.

Mulitple Groups

Avatar

Level 1
Hi,

I'm writing an app that will have multiple groups. I want
each group to have properties, like groupType for example.

What's the best way to handle that? With a sharedModel, by
sending an object in a messageItem after node creation, or some
other way that's probably totally obvious?
4 Replies

Avatar

Level 1
sorry, I meant sharedCollection, not sharedModel.

Avatar

Former Community Member
Hi,

The question sounds interesting. We have an example in
examples folder called MultipleGroups which has a model called
MultipleGroupModel . The model has a collection that keeps track of
all users in a particular group.

For any new property specific to a group, I would publish it
as an Item on the groupName node ( see MultipleGroupModel file) and
in my model I will do a bookkeeping by having a property object for
that property indexed by groupName. Something like this,



I will have

_collectionNode.publish Item(new
MessageItem(groupName,propertyVal, propertyName));



In my model I will have an object lets say called
propertyNameObject["groupName"] = propertyVal



I will populate this object in itemReceive with something
like this,

if ( p_evt.item.itemID == propertyName ) {

propertyNameObject[p_evt.nodeName] = p_evt.item.body ;

}



In this way , you can have any new property associated with a
particular group.



Of course , prior to doing all this you need to have a shared
model like MultipleGroupModel and create the collectionNode and
groups(nodes) for that model. Refer to the example and the
MultipleGroupModel file for details.



Hope this helps.

Thanks

Hironmay Basu

Avatar

Level 1
Thanks for the reply.



I've been using the MultipleGroups example as a model for my
app.

I understand your suggestion. Thanks.



What are your thoughts on using a sharedCollection as a
solution with the groupName as the idField? I was thinking I would
also use one for users. Are there any guidelines for when to use
sharedCollections vs objects in messages?

Avatar

Former Community Member
Hi,



As you have seen, SharedCollection is just another shared
model specifically useful for Lists and DiataGrid as it exposes a
shared ListCollectionView. The Pro's of using it are having methods
for adding, removing , changing the dataCollection and cons are
having ListCollectionView overhead. Normally, if I am just using my
model for specfic purposes I would build it like the
MultipleGroupModel from scratch that extends EventDispatcher and
not use mx classes, but you can also use SharedCollection with
idField as groupName for your purpose I think.



Thanks

Hironmay Basu