Solved

arrayCollection Grouping for comboBox

Posted on 2011-03-14
1
499 Views
Last Modified: 2012-08-13
How to group items in an array collection so my combobox does not repeat the duplicat items. I have don this with a datagrid but can not seem to get to work with a combobox.
0
Comment
Question by:kpjj31
1 Comment
 
LVL 29

Accepted Solution

by:
dgofman earned 500 total points
ID: 35134376
You may not need to use a groupCollection,
You can use an Array filter.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" initialize="init()">
	<fx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;

			private var _original:Array = new Array(
					{label:"One", data:1},
					{label:"Two", data:2},
					{label:"Three", data:3},
					{label:"One", data:1}
			);
			
			private function init():void{
				var keys:Object = {};
				var filteredArr:Array = _original.filter(function(item:Object, idx:uint, arr:Array):Boolean {
					if (keys.hasOwnProperty(item.data)) {
						return false;
					} else {
						keys[item.data] = item;
						return true;
					}
				});
				cmb_uniq.dataProvider = new ArrayCollection(filteredArr);
			}
		]]>
	</fx:Script>
	<s:ComboBox id="cmb_uniq"/>
</s:Application>

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question