I need to find the index of a linkbar, only got the label. Like array.indexOf(value) ?
You can iterate through the objects in the LinkBar's dataProvider and check for a match. This is dependent upon the structure of the objects in the dataProvider. If they are simply strings in an array, you can do pretty much what you stated in your question:
(myLinkBar.dataProvider as Array).indexOf(value);
Hope that helps.
Related
I have a Flex project. I want to dynamically create mx.controls.Image objects and add them to the display. However, the number of images and it properties deponds on the value stored in a database. Hence, I have to connect to the database,read the values for data table, then create objects dynamically according the values.
Then, I wonder if this is possible and how to do this.
Thanks in advance.
Felix
Just try declaring a variable as *.
Like var any:*; And check always for null. So it will take any type of value.
Hope it will help.
I have a problem with the AdvancedDataGrid widget. When the dataProvider is an ArrayCollection (of arrays), the nth array (within the collection) is also the nth row within the grid, and I can jump and display the i-th row by scripting
adg.selectedIndex = i;
adg.scrollToIndex(i);
now, when I add a Grouping, the dataProvider ends up being a GroupingCollection2, and now the index in the dataprovider's source does not correspond to the index in the adg anymore (which is understandable, because it's being grouped).
How can I select and display a row in grouped data efficiently? Currently, I have to traverse the adg and compare each found item with its data attributes in order to find the correct index of the row within the adg, and jump to it like above. This process is very slow. Any thoughts?
edited later:
We already used a caching object as Shaun suggests, but it still didn't compensate for the search times. In order to fully construct a sorting of a list of things (which this problem equates to, as the list is completely reordered by the grouping), you always have to know the entire set. In the end we didn't solve that problem. The project is over now. I will accept Shaun's answer if no one knows a better way in three days.
Depending on what values your comparing against you can store the objects in a dictionary with the lookup using the property/properties that would be searched for, this way you have a constant time look-up for the object (no need to look at every single item). Say for example your using a property called id on an object then you can create an AS object like
var idLookup:Object = {};
for(myObject in objects)
idLookup[myObject.id] = myObject;
//Say you want multiple properties
//idLookup[myObject.id]={};
//idLookup[myObject.id][myObject.otherProp] = myObject;
now say the user types in an id you go into the idLookup object at that id property and retrieve the object:
var myObject:Object = idLookup[userInput.text];
myAdg.expandItem(myObject, true);
now when you want to get an object by id you can just do
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/AdvancedDataGrid.html#expandItem()
I haven't done any thorough testing of this directly, but use a similar concept for doing quick look-ups for advanced filtering. Let me know if this helps at all or is going in the wrong direction. Also if you could clarify a bit more in terms of what types/number of values you need to lookup and if there's the possibility for multiple matches etc. I may be able to provide a better answer.
Good luck,
Shaun
I have a Dictionary that I'd like to bind as the dataProvider for an mx:ComboBox. e.g., when I do this:
mydict[somenewkey]= somenewval;
I'd like the combobox to update its contents.
The problem is that Dictionary doesn't seem to be Bindable. If I were using an Array, I'd use ArrayCollection. But there doesn't seem to be a corresponding DictionaryCollection or HashCollection. What to do?
A Dictionary is not the appropriate object for a dataProvider of a list based class.
I suspect your display problems have nothing to do with data binding, but rather other issues, such as a dictionary does not have a length property.
I suspect the ComboBox will treat your dictionary as a single object, not as a collection of multiple objects.
Try using an ObjectProxy:
http://www.adobe.com/livedocs/flex/3/langref/mx/utils/ObjectProxy.html
Isn't what you're looking for just a combination of the setItemAt and getItemIndex methods of the ArrayCollection?
_myAC.setItemAt( somenewval, _myAC.getItemIndex( somenewkey ) );
Should be easy but google couldn't give me a straight answer. I have an array. The fields in the array have underscores that I would like to remove e.g. "Column_1" to "Column 1". Does anyone know a good way to do this without looping through the whole array and rebuilding it anew? I didn't see any methods in the reference that would make this easy. thx
Depending on where you are using this Array, you could use the labelFunction to format the data before presenting it. It is present in Lists, DataGrids and Trees.
But you'd only need this if you have a very large data and wouldn't want to loop over all the records before showing them. A labelFunction would "reprocess" the label everytime before it's presented.
Flex 3 has built in refactoring
Edit... I may have misunderstood..
If you want to format the data in the array just loop through it and use regex to remove the underscores... or you can modify your query which grabs the data (if it is populated from a query)
I have a flex datagrid. it is bound to an array collection. if the user sorts on column X it works fine. then, if the user causes the array collection to change, the datagrid forgets that it was sorted on column X.
what do I need to do to preserve this sort preference so that the new array data will appear sorted by column X?
I posted this question on another forum and got a good answer that worked well. Here it is:
If your data is in ArrayCollections you can assign a ListCollectionView to the dataProvider property of your child AdvancedDataGrid and assign your ArrayCollection data to the 'list' property of the ListCollectionView. When you want to change the data in the child grid, reassign the list property of the ListCollectionView. This way you avoid reassigning the dataProvider of the child grid directly, which is what causes the grid to reset.
here's the link to the post:
http://forums.adobe.com/message/2206736#2206736
That really helped, thanks. But don't forget to Refresh() the dataProvider once you have reset the sort:
dataGrid.dataProvider.refresh();
I have same kind of problem but didnt knw why it was happening so did some tweaking
selectedItems=dataGrid.selectedItems;
postionGrid=dataGrid.verticalScrollPosition;
sortPostionGrid=dataGrid.dataProvider.sort;
store them in a variable and when data is changed just put the again on the grid it is not a good approach but it worked for me
This post "Keeping the sort on a datagrid when you change the dataProvider" gives
more relevant and efficient solution what you looking for
Hopes that helps