English 中文(简体)
灵活性行动说明中的怀疑:从阿雷拉角获得独特的要素
原标题:Doubt in action script for Flex: getting unique elements from an ArrayCollection

我有下文提及的阿雷拉角。

        private var initDG:ArrayCollection = new ArrayCollection([
            {fact: "Order #2314", appName: "AA"},

            {fact: "Order #2315", appName: "BB"}

            {fact: "Order #2316", appName: "BB"}
                            ...

            {fact: "Order #2320", appName: "CC"}

            {fact: "Order #2321", appName: "CC"}

            ]);

我想用UNI Request VALUES从ArrayCollectioninitDG的“appName”领域向ComboBox居住。

<mx:ComboBox id="appCombo" dataProvider="{initDG}" labelField="appName"/>

我认为,一种办法是穿透Array物体和每个物体的检查,并将独一无二的对应条目推入另一个Array。 是否有更好的解决办法?

问题回答

这对我有利:

var unique:Object = {};
var value:String;
var array:Array = initDG.toArray();
var result:Array = [];
var i:int = 0;
var n:int = array.length;
for (i; i < n; i++)
{
 value = array[i].appName;
 if (!unique[value])
 {
  unique[value] = true;
  result.push(value);
 }

}
return new ArrayCollection(result);

你们可以利用这一类别寻找独特的阵列收集:

tempArray=_uniqueArray.applyUnqiueKey1(_normalsearchdata.toArray());

“unique Array”是指包裹名称和——热研究数据为ArrayCollection;

package{
    import mx.collections.ArrayCollection;
    public class applyUniqueKey{
        private var tempArray:Array;

        private var tempIndex = 0;
        public var temp:String;
        public function applyUnqiueKey1(myArray)

        {
            tempArray = new Array();
            tempIndex = 0;  
            myArray.sort();
            tempArray[0] = myArray[0];
            tempIndex++;

            for(var i=1; i<myArray.length; i++) {
                if(myArray[i] != myArray[i-1]) {
                    tempArray[tempIndex] = myArray[i];
                    tempIndex++;
                }
            }
            var temp=String(tempArray.join());
            return new ArrayCollection(tempArray);
        }
    }
}

地图册中不存在独一无二的()法,但可以大致如此:

var names:Array = initDG.toArray().map(
    function (e:Object, i:Number, a:Array):String {
        return e.appName;
    }
);

var uniqueNames:Array = names.filter(
    function (name:String, i:Number, a:Array):Boolean {
                // Only returns true for the first instance.
        return names.indexOf(name) == i;
    }
);

值得注意的是,这项工作之所以发生,是因为你正在对地块进行过滤,而后者的价值比较。 如果你需要过滤任意物体,那就没有效果。





相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Multiple Remote call made simultenously

I was making multiple remote calls and they are done sequentially and when I am getting a result event back it s triggering calls to all the methods with ResultEvent as an argument . I am supposed to ...

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Clearing RSL in Cache

I have built a flex application which has a "main" project and it is assosciated with a few RSL s which are loaded and cached once i run my "main" application. The problem i am facing is that the ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签