Solved

arrayCollection Grouping for comboBox

Posted on 2011-03-14
1
488 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to count occurrences of each item in an array.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now