Merge data into filtered ArrayCollection (maybe by using IViewCursor or localIndex?)

后端 未结 1 761
南旧
南旧 2021-01-16 07:44

I have a Flex question, which isn\'t as easy as it seems at first.

At least I\'m struggling since 1 week with it.

I have prepared a test case and a screensho

1条回答
  •  误落风尘
    2021-01-16 08:08

    Try to operate ArrayCollection's source property the following way:

    
    
    
        
            
        
    
        
        = 0; i--)
                {
                    for (j = data.length - 1; j >= 0; j--)
                    {
                        if (sourceData[i] == data[j])
                            continue found1;
                    }
                    var index:int = _data.getItemIndex(sourceData[i]);
                    if (index > -1)
                        _data.removeItemAt(index); // remove visible items
                    else
                        sourceData.splice(i, 1); // remove hidden (filtered) items
                }
    
                // 2) add items appeared in data to _data
                found2: for (j = 0; j < data.length; j++)
                {
                    for (i = 0; i < sourceData.length; i++)
                    {
                        if (sourceData[i] == data[j])
                            continue found2;
                    }
                    _data.addItem(data[j]);
                }
            }
    
            private function radioClicked(event:Event):void
            {
                switch (filterGroup.selection)
                {
                    case allButton:
                    {
                        _data.filterFunction = null;
                        break;
                    }
                    case oddButton:
                    {
                        _data.filterFunction = filterOdd;
                        break;
                    }
                    case evenButton:
                    {
                        _data.filterFunction = filterEven;
                        break;
                    }
                }
                _data.refresh();
            }
        ]]>
        
    
        
            
        
    
        
            
            
            
            
        
    
        
    
        
        
        
        
        
        
    
    
    

    And a couple of advices on using RadioButton and RadioButtonGroup:

    • Do not use click events to handle changes. This disables possibility to manage buttons other way (from keyboard for example). Use change instead.
    • If you are using RadioButtonGroup it is better to refer group rather than groupName. It gives you possibility to check problems on compile time (imagine some misprints in group name).
    • Do not check selected button against label. You can misprint label name or you can change label etc. and compiler can't help you in that.

    0 讨论(0)
提交回复
热议问题