Solved

arrayCollection Grouping for comboBox

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

790 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