Arraycollection into XMLlistcollection
Hi all,
I am trying to create my xmllistcollection since days, and getting soo unsuccessful each time...
I have a flat simple arraycollection like :
id_order
client_name
orders_name
1
client_name 1
order_name 1
2
client_name 2
order_name 2
3
client_name 3
order_name 3
4
client_name 1
order_name 4
Objective: I want to display the above data in a tree, group by client_name.
Please can you help me to create that xmllistcollection ?
Thanks
ps: what i have done so far:
[Bindable]
private var myXMLlist:XML = <clients></clients>;
[Bindable]
private var XMListcol:XMLListCollection;
private function createXML():void
XMListcol = new XMLListCollection;
var clientNamePrev:String;
for (var i:int = 0; i < allOrders_array.length; i++)
var ordName:String = allOrders_array.getItemAt(i).orders_name;
var idOrders:String = allOrders_array.getItemAt(i).id_orders;
var clientName:String = allOrders_array.getItemAt(i).client_name;
var clientNameTag:XML = <clientname>{clientName}</clientname>;
//Alert.show("idOrders:"+ idOrders+ "order name:"+ ordName);
var new0rderTag:XML = <ordername id={idOrders}>{ordName}</ordername>;
if(clientNamePrev == clientName)
Alert.show("clientNameTag: "+ clientNameTag);
clientNameTag.appendChild(new0rderTag);
else
//Alert.show("ord Prev: "+clientNamePrev + " orderName: "+ clientName);
myXMLlist = myXMLlist.appendChild(clientNameTag);
clientNamePrev= clientName;
XMListcol = new XMLListCollection(myXMLlist.children());
Alert.show("listxml: "+ myXMLlist.descendants());
Hi
Do you know how could i access the attribute 'id' from the tag '<ordername id =xx>'?
please find below the solution to my difficulties:
private function createXML():void
var myXMLlist:XML = <clients></clients>;
var clientNamePrev:String = "";
var clientNameTag:XML;
//Alert.show("arraylength : " +allOrders_array.getItemAt(20).client_name );
for (var i:int = 0; i < allOrders_array.length; i++)
var ordName:String = allOrders_array.getItemAt(i).orders_name;
var idOrders:String = allOrders_array.getItemAt(i).id_orders;
var clientName:String = allOrders_array.getItemAt(i).client_name;
var new0rderTag:XML = <ordername id={idOrders} label={ordName}/>;
if (clientNamePrev == "")
clientNameTag = <clientname label={clientName}></clientname>;
clientNameTag.appendChild(new0rderTag);
else if(clientNamePrev == clientName)
clientNameTag.appendChild(new0rderTag);
//Alert.show("clientNameTag: "+ clientNameTag);
else if(clientNamePrev != clientName)
//Alert.show("ord Prev: "+clientNamePrev + " orderName: "+ clientName);
myXMLlist = myXMLlist.appendChild(clientNameTag);
clientNameTag = <clientname label={clientName}></clientname>;
clientNameTag.appendChild(new0rderTag);
else
Alert.show("Please contact Administrator @ [email protected]", "Alert");
if (i == (allOrders_array.length - 1))
myXMLlist = myXMLlist.appendChild(clientNameTag);
clientNamePrev= clientName;
XMListcol = new XMLListCollection(myXMLlist.children());
//Alert.show("listxml:" + XMListcol);
Thank you
Similar Messages
-
Arraycollection to xmllistcollection
Is there an easy way to convert an ArrayCollection to an
XMLListCollection? I have found plenty of references to convert the
reverse, but none that go into an XMLListCollection or XMLList.
I am receiving a query from a database via a RemoteObject and
putting it directly into an ArrayCollection. Some of this data
needs to be displayed in a Tree and I've found XMListCollection
works better as a data provider. I wrote a method to go through the
array and create nodes then add them to the XML, but it seems there
would be a way to do this automatically instead. Thanks!You cannot cast unless the cariable you are casting contains
an object of the type you are casting to.
ArrayCollection will never contain an XMLListcollection, so
forget casting.
If the CFC IS returning xml, then set the resultFormat="e4x",
then in the handler, do:
var xmlResult:XML = XML(event.result);
trace(xmlResult.toXMLString())
Tracy -
Issue Putting Data from ArrayCollection into List
I'm having trouble getting data that has been pulled from a textArea and put into an ArrayCollection to be displayed in a List. The data is being saved and then read as a file from local storage. When I run the application, nothing appears in the created list even though I get no compile-time errors.
Here is my List code:
<fx:Script>
<![CDATA[
import dh.DataHandling;
import mx.collections.ArrayCollection;
import mx.collections.ArrayList;
import mx.events.FlexEvent;
import spark.effects.SlideViewTransition;
[Bindable]
private var dataR:DataHandling = new DataHandling();
protected function button1_clickHandler(event:MouseEvent):void // pushed home button
var svt:SlideViewTransition = new SlideViewTransition(300, SlideViewTransition.SLIDE_RIGHT);
navigator.pushView(views.HomePage, event.relatedObject, svt);
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:actionContent>
<s:Button label="Delete"/>
<s:Button label="Home" click="button1_clickHandler(event)" skinClass="skins.homeButtonSkin"/>
</s:actionContent>
<s:Image x="0" y="-80" height="603" source="mainapp1.jpg"/>
<s:List id="myCardsList" x="10" y="10" width="1004" height="500" top="0" bottom="0" left="0" right="0"
dataProvider="{dataR.cards as ArrayCollection}">
<s:itemRenderer>
<fx:Component>
<s:MobileIconItemRenderer label="{data.textTitle}"/>
</fx:Component>
</s:itemRenderer>
</s:List>
Here's the "saving/reading the file" class used in creating the ArrayCollection: ( DataHandling.as )
package dh
public class DataHandling
import flash.events.IOErrorEvent;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import mx.collections.ArrayCollection;
[Bindable]
public var cards:ArrayCollection = new ArrayCollection();
public var file:File;
public var fileStream:FileStream;
public var fileName:String = "Initial String";
public var directory:String = "SimpleSaveFromAIR";
public var textTitle:String;
public function DataHandling()
public function add():void
// new object
var card:Object = new Object();
card.tcard = textTitle;
//card.mtext1 = mtext1.text;
///card.mtext2 = mtext2.text;
cards.addItem(card);
public function save():void
// create file object (resolve user's directory, add own directory)
file = File.documentsDirectory.resolvePath(directory + "\\" + fileName);
// FileStream for writing the file
fileStream = new FileStream();
// open the file in write mode
fileStream.open(file, FileMode.WRITE);
// Write the ArrayCollection object of cards to the file
fileStream.writeObject(cards);
// close stream
fileStream.close();
public function read():void
// get correct path
file = File.documentsDirectory.resolvePath(directory + "\\" + fileName);
// read if exists
if(file.exists)
// FileStream for reading the file
fileStream = new FileStream();
// open the file in read mode
fileStream.open(file, FileMode.READ);
// Read the ArrayCollection object of cards from the file
cards = fileStream.readObject() as ArrayCollection;
//close Stream
fileStream.close();
else
// some sample data + save if file does not exist
cards = new ArrayCollection();
var card:Object = new Object();
card.tcard = "Sample Title";
card.mtext1 = "Sample Text";
cards.addItem(card);
save();Off topic: I noticed you are binding the label value of the renderer to the data. It's recommended that you use the labelField property on the List instead for better performance on mobile, for example:
<s:List id="myCardsList" labelField="textTitle" ...>
<s:itemRenderer>
<fx:Component>
<s:MobileIconItemRenderer />
</fx:Component>
</s:itemRenderer>
</s:List> -
Why is it different using ArrayCollection and XMLListCollection?
As shown in the screenshot below. The first one has ArrayCollection as dataProvider. The second one has XMLListCollection as dataProvider.
I would like the result for XMLListCollection but now I only have ArrayCollection as input. How can I deal with it? Thanks!
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" >
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var dp:ArrayCollection = new ArrayCollection([
{name: "00:00:00", v1: "2"},
{name: "00:15:00", v1: "3"},
{name: "00:30:00", v1: "4"},
{name: "00:45:00", v1: "3"},
{name: "01:00:00", v1: "5"},
{name: "01:15:00"},
{name: "01:30:00"},
{name: "01:45:00"},
{name: "02:00:00"}
]]>
</mx:Script>
<mx:XMLListCollection id="dp2">
<mx:source>
<mx:XMLList>
<hour name="00:00:00" v1="2"/>
<hour name="00:15:00" v1="3"/>
<hour name="00:30:00" v1="4"/>
<hour name="00:45:00" v1="3"/>
<hour name="01:00:00" v1="5"/>
<hour name="01:15:00" />
<hour name="01:30:00" />
<hour name="01:45:00" />
<hour name="02:00:00" />
</mx:XMLList>
</mx:source>
</mx:XMLListCollection>
<mx:LineChart id="lineChart" height="100%" width="100%" dataProvider="{dp}" showDataTips="true">
<mx:horizontalAxis>
<mx:CategoryAxis categoryField="name"/>
</mx:horizontalAxis>
<mx:series>
<mx:LineSeries yField="v1" form="curve" displayName="v1"/>
</mx:series>
</mx:LineChart>
<mx:Legend dataProvider="{lineChart}" direction="horizontal"/>
<mx:LineChart id="lineChart2" height="100%" width="100%" dataProvider="{dp2}" showDataTips="true">
<mx:horizontalAxis>
<mx:CategoryAxis categoryField="@name"/>
</mx:horizontalAxis>
<mx:series>
<mx:LineSeries yField="@v1" form="curve" displayName="v1"/>
</mx:series>
</mx:LineChart>
<mx:Legend dataProvider="{lineChart2}" direction="horizontal"/>
</mx:Application>Define a default value to v1 for each of your objects in the ArrayCollection, or even better, use a strongly typed model class. In XML this would resolve to null (or maybe an empty string?), but an object will throw a "property not found" error, which may have unexpected results (as seen above).
-
Adding Item into XMLListCollection
Hi
I store my data into a XMLListCollection variable (name XC).
The initial lengt of this XMLListCollection is 10 items (for
example: XC.length==10). I leave the user to filter this data and I
added a filterfunction to this variable. I set another function
named sync() that run every 10 seconds (for example). This function
is trying to insert an element into XC:XMLListCollection at a
specific position (for example 8 XC.additemat(item,8)). After the
user filter the data, the length is 2 and when the sync() function
is activated, this function call "addItemAt(item,8)" and I receive
"Index out of Bound...".
I know how to read the entire list (XMLList) using the
.source properties but I don't know how to insert an element at a
specific position (for example 8).
Please help me (if you know)
Thanks in advance
CristyI want to store this variable on the local disk into a
SharedObject. So, if I stored the entire collection (with 10
items), and the server send to the user another item I want to
insert this item into the collection even the item received from
the server is not visible by the user (because of filtefunction).
When the user want to save the data I want to use
sharedobject.flush() and I expect to save the entire collection (11
items). When the user enter again in this form I want to show 11
items and the user can filter this items in multuple ways. Thanks
for your replay.
Cristy -
How to convert arraycollection into HierarchicalData?
Hi,
Anyone can tell that how to convert arraycollection(flat data) into HierarchicalData? Thanks in Advance.i give a example below. it conver flat arraycollection data and display in hierarchical manner in datagrid
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var myAC:ArrayCollection = new ArrayCollection([
{category:'Friends', name:'Jon Hirschi', email:'[email protected]'},
{category:'Friends', name:'Frank Krul', email:'[email protected]'},
{category:'Friends', name:'Ryan Stewart', email:'r_stewart'},
{category:'Family', name:'Zafira Ahmed', email:'[email protected]'},
{category:'Family', name:'Shiraz Ahmed', email:'[email protected]'}]);
]]>
</mx:Script>
<mx:GroupingCollection id="myGC" source="{myAC}">
<mx:Grouping>
<mx:GroupingField name="category"/>
</mx:Grouping>
</mx:GroupingCollection>
<mx:AdvancedDataGrid dataProvider="{myGC}" initialize="myGC.refresh()"
width="300">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="name" headerText="Contacts"/>
<mx:AdvancedDataGridColumn dataField="email" headerText="Email"/>
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Application>
If this example helps in ur question then give me mark. -
Export ArrayCollection into XML file
Hello all,
Is it at all possible to export an ArrayCollection from Flex, into a XML file.
My array collection is being viewed in a datagrid as follows
<mx:DataGrid x="360" y="120" width="448" height="200" dataProvider="{questionsArr}">
<mx:columns>
<mx:DataGridColumn headerText="Question" dataField="question"/>
<mx:DataGridColumn headerText="Start" dataField="start" width="40" textAlign="center"/>
<mx:DataGridColumn headerText="Stop" dataField="stop" width="40" textAlign="center"/>
</mx:columns>
</mx:DataGrid>
And i want the output of the XML to look like this
<Cue>
<section question="" start="" stop=""/>
<section question="" start="" stop=""/>
<section question="" start="" stop=""/>
</Cue>
Is it at all possible ? I mean all the data is there ready, it just needs to be saved . .Hi djh88ukwb,
Check out the link below, it shows an example as how to convert ArrayCollection to Object:
http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simple xmlencoder-class-in-flex/#more-543
Thanks,
Bhasker Chari -
XMLListCollection vs. ArrayCollection
Hello,
I was recently speaking with a colleague about the merits of
working with native XML across client and server tiers of a Flex
app vs. marshaling/unmarshaling XML to/from objects, and he
mentioned that in his experience, the performance of working with
ArrayCollections was much better than that of XMLListCollections,
up to an order of magnitude or better. So I Googled a bit, and I
found this:
http://blog.fastlanesw.com/?p=14
This is a blog post that references some apparent comments
from someone from Adobe on this very issue, and suggests that E4X
may be a liability, at least from a memory standpoint. Between my
colleague's experiences and recommendations, and this blog post, it
raises the following questions:
1) Is there indeed a significant performance and/or memory
penalty for using E4X/XMLListCollections?
2) If the answer to 1) is yes, is this a design flaw, and
will be fixed at some point, or no?
3) If the answer to 1) is yes, then when would ever using E4X
be advisable? It seems the using E4X in general would be a
liability.
My particular reason I am asking is a fairly standard one. I
am trying to determine if it is wiser to orient client and server
architecture code to standard AS3 class objects, and marshal in and
out of xml when communicating between client and the server (i.e.
XML over the wire but objects, but after crossing the wire, marshal
out of XML to AS3 objects into ArrayCollections, and data bind the
UI to objects); OR, orient the client and server to native xml, and
use native XML not only across the wire, but E4X to marshal into
XMLListCollections and data bind to these objects instead. Native
XML structures and E4X on the client seem very attractive, as it
eliminates a lot of the trouble in having to code
marshaling/unmarshaling. But if it comes with a major
performance/memory price, then it is probably a bad architectural
idea. Customers don't much care about ease of development, they
want a stable, performant app.
Can anyone speak definitively to this?
Thanks!
BradYes I meant query. By' bringing it in' I mean it's bringing in an actionscript object.
So any query including using an arrayList (like the following) would be converted to an XMLlist?
I thought arrayLists are separate from XMLLists.
<fx:Declarations>
<fx:Model id="categoryModel" source="data/categories.xml"/>
<s:ArrayList id="categoryCollection" source="{categoryModel.category}"/>
</fx:Declarations>
<mx:DataGrid id="categoryGrid" dataProvider="{categoryCollection}"/>
In any case I'm still not sure why you would need to use an XMLCollection since you can use an ArrayCollection. -
Converting arrayCollection values into String
Hi,
In my application, the dataprovider of a datagrid which is an arraycollection receives values of objects. I need to get them as string variable so as to convert a particular column in the arraycollection as a string variable of comma seperated values.
I am not too good with flex. Can someone please help me..?
I have three AS classes :
First Class
package script.vo
public class SectorsVO
public function SectorsVO()
public var sectorId:Number;
public var sectorName:String;
public var fromStation:StationsVO;
public var toStation:StationsVO;
Second class
package script.vo
public class StationsVO
public function StationsVO()
public var stationCode:String;
public var stationName:String;
public var countryCode:CountryVO;
Third class
package script.vo
public class CountryVO
public function CountryVO()
public var countryCode:String;
public var countryName:String;
My mxml page is :
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/19/dragging-rows-between-two-different-flex-datagrid- controls/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="horizontal"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import script.vo.SectorsVO;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
[Bindable]
public var sectors:ArrayCollection = new ArrayCollection([{sectorId:101,fromStation:"Calicut",toStation:"Muscat"},
{sectorId:102,fromStation:"Kochi",toStation:"Sharjah"},
{sectorId:103,fromStation:"Bangalore",toStation:"Dubai"},
{sectorId:104,fromStation:"Dubai",toStation:"Amman"},
{sectorId:105,fromStation:"Amman",toStation:"Frankfurt"}]);
[Bindable]
public var draggedSectors:ArrayCollection = new ArrayCollection();
public var mySectors:SectorsVO = new SectorsVO;
public var myString:String = "";
private function getValuesAsCSV():void{
for(var i:int = 0; i < draggedSectors.length; ++i){
mySectors = SectorsVO(draggedSectors.getItemAt(i));
Alert.show("Value is : "+mySectors.sectorId);
myString = String(mySectors.fromStation.stationName);
Alert.show("Sector name :"+myString);
]]>
</mx:Script>
<mx:VBox width="50%">
<mx:Label text="Stations" />
<mx:DataGrid id="dataGrid1" width="100%" rowHeight="22" dataProvider="{sectors}" dragEnabled="true" dragMoveEnabled="true"
dropEnabled="true" verticalScrollPolicy="on">
<mx:columns>
<mx:DataGridColumn dataField="fromStation" headerText="From Station" />
<mx:DataGridColumn dataField="toStation" headerText="To Station" />
</mx:columns>
</mx:DataGrid>
<mx:Label text="{dataGrid1.dataProvider.length} items" />
</mx:VBox>
<mx:VBox width="50%">
<mx:Label text="DataGrid #2" />
<mx:DataGrid id="dataGrid2" width="100%" rowHeight="22" dragEnabled="true" dragMoveEnabled="true" dropEnabled="true"
verticalScrollPolicy="on" dataProvider="{draggedSectors}" >
<mx:columns>
<mx:DataGridColumn dataField="fromStation" headerText="From Station" />
<mx:DataGridColumn dataField="toStation" headerText="To Station" />
</mx:columns>
</mx:DataGrid>
<mx:Label text="{dataGrid2.dataProvider.length} items" />
<mx:Button id="getValues" click="getValuesAsCSV()" label="Get Sectors" enabled="{dataGrid2.dataProvider.length>0}"/>
</mx:VBox>
</mx:Application>
My prime issue is to convert the values in the arraycollection into String variables.
Please help me on the ablve matter..! Thanks in advance..!fromStation and toStation are already Strings, but you are attempting to cast an ArrayCollection entry to a SectorsVO object. The problem is that SectorsVO has a no-arg constructor and the entry that you are attemping to cast is not of type SectorsVO. You need to modify the constructor to accept an Object and manually assign values to the properties.
It sounds like you are trying to build a CSV string out of all of the values of one of the fields. What you can do is loop through the draggedSectors and pull out the desired property, placing it into a temporary Array. After the loop, simply use Array.join(",") to produce a CSV string. -
Cannot read an ArrayCollection variable assigned by LCDS
Hi,<br /><br /> I am new to flex and lcds. pls. help me to understand. All I am trying to do here is take the hibernate sample from lcds sample application and replace the grid control with a tree control. In order achieve this, I was trying to convert the ArrayCollection into an XMLListCollection object through an actionscript in a function called convertToXML. How ever, I'm having the difficulty in this conversion. When i tried to debug the action script, the arraycollection, which is suppose to be with full values, seems to empty. But, still it shows up the records in the grid. pls. help to understand, why, I can't manipulate the ArrayCollection?<br /><br /> For your reference, Following is the modifed modified lines of the original lcds sample code.<br /><br /><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*" layout="absolute" <br /> width="100%" height="100%"<br /> pageTitle="Hibernate"<br /> creationComplete="convertToXML()"><br /><br /> <!--<br /> <mx:Tree id="list" width="100%" height="100%" dataProvider="{projectData}" labelField="@name"/><br /> --><br /> <mx:DataGrid id="list" width="100%" height="100%" dataProvider="{contacts}"<br /> doubleClick="openTab(list.selectedItem as Contact)" doubleClickEnabled="true"><br /> <mx:columns><br /> <mx:DataGridColumn dataField="firstName" headerText="First Name"/><br /> </mx:columns><br /> </mx:DataGrid><br /><br /> [Bindable]<br /> private var projects:XML =<br /> <list><br /> <projects name="Projects" code="0"><br /> </projects><br /> </list>;<br /><br /> [Bindable]<br /> private var projectData:XMLListCollection = <br /> new XMLListCollection(projects.projects);<br /> <br /> private function convertToXML():void {<br /> ds.fill(contacts, 'all', []);<br /> for each (var proj:Contact in contacts) {<br /> addProject(proj.lastName + ", " + proj.firstName); <br /> } <br /> }<br /> <br /> private function addProject(projName:String):void {<br /> var newNode:XML = <project/>;<br /> newNode.@name = projName;<br /> var proj:XMLList = projects.projects.(@name == "Projects");<br /> if( proj.length() > 0 ) {<br /> proj[0].appendChild(newNode);<br /> }<br /> }<br /><br /> private function treeLabel(item:Object):String {<br /> var node:XML = XML(item);<br /> if( node.localName() == "department" )<br /> return node.@title;<br /> else<br /> return node.@name;<br /> }
If I understand correctly you must read a BLOB from a foregin database but have no privleges to create any supporting objects. This sounds painful.
Options to get to the BLOB include (all with problems to solve)
* through database link
* extract LOB to OS and re-load into database
**flat file
**datapump file
Some options - I hope someone provides better ideas, but until that happens ...
Can you create objects on the other side - where the BLOB comes from? If you can, consider writing a (pipelined?) function to read the BLOB, chop it up into smaller pieces, transfeer the pieces over a database link, and reassemble the pieces in the remote database using DBMS_LOB in PL/SQL. Not elegant.
You should be able to use the scheduler to create a job to use datapump to extract the BLOB and possibly transfer it too but how to access the OS file? You said you have no privileges to create objects, and that would include external tables. Could you find an existing directory object and use the folder already defined (risky; using a different application's infrastructure can be hard to maintain and will break when the underlying directly goes away)?
Edited by: riedelme on Jun 13, 2011 12:08 PM -
From ArrayCollection to Array in DataBinding
Hi,
I am trying to use somebody else's visual component (have src code of that mxml),
which uses Array items as a DataSource.
In my program I use ArrayCollection to hold my data (from the data feed - changes in real time).
I need to pass some data from my ArrayCollection into that component inside the binding,
something like:
<view:Component1 items="{dataArrayCollection}"?? />
currently have in Component1.mxml:
public function set items(a:Array):void {...}
Since that component is pretty complicated, I would not want to break its logic,
so I am thinking of adding some data adapter, public method to Component1 like:
public function set dataProvider(ac:ArrayCollection):void {
Array tempArr = new Array();
// copy some data from ac -> tempArr
items(tempArr);
and do: <view:Component1 dataProvider="{dataArrayCollection}" />
Is there a more efficient way of doing that (I guess, "set dataProvider" will be called a lot, on each update)?
I don't think I can just straight convert ArrayCollection -> Array, need just a small subset of data.
Please advise.
TIA,
Oleg.Alex,
A friend suggested me another solution, which I tried and it seems to work and be more straightforward:
main.xml:
[Bindable]
private var ac : ArrayCollection;
<component dataProvider="{ac}" />
Component.xml:
[Bindable]
public var dataProvider:ArrayCollection;
private function onCreationComplete():void {
dataProvider.addEventListener(CollectionEvent.COLLECTION_CHANGE, onDataProviderUpdate);
public function onDataProviderUpdate(e:*=null):void {
if (dataProvider == null) {
return;
var aca:Array = dataProvider.source;
var dev1:Object = aca[0]; // process only 1 element of that AC
var dev:Device = new Device();
dev.cpu = dev1["cpu"];
// pass to items array
if (_items == null) { // if new // _items - component's data array
_items = new Array();
_items.push(dev);
} else {
_items.push(dev);
updateData();
updateView();
Do you like that solution ?
The only problem I see is that when the feed runs, the size of the browser memory grows fast,
so by element 60 it slows down, by 95 memory consumption grows to 1.4GB and browser crashes.
I do not think it is related to that data binding, but not positive.
Can it be array.push() ?
Any way to force garbage collection in Flex ?
Please advise,
Oleg. -
A Challenge - Re-Arranging an ArrayCollection
I am displaying data from an ArrayCollection (dynamically generated) into an Advanced DataGrid. The ArrayCollection (of objects) which looks something like this:
{ date:"2009-11-08", visitors:"252678", name:"Sitename1"}, // On this day, Sitename1 got 252678 visitors
{ date:"2009-11-09", visitors:"655378", name:"Sitename1"},
{ date:"2009-11-10", visitors:"452648", name:"Sitename1"},
{ date:"2009-11-11", visitors:"282678", name:"Sitename1"},
{ date:"2009-11-12", visitors:"315267", name:"Sitename1"},
{ date:"2009-11-13", visitors:"695135", name:"Sitename1"},
{ date:"2009-11-14", visitors:"659862", name:"Sitename1"},
{ date:"2009-11-08", visitors:"598754", name:"Sitename2"}, // On this day, Sitename2 got 598754 visitors
{ date:"2009-11-09", visitors:"255378", name:"Sitename2"},
{ date:"2009-11-10", visitors:"268554", name:"Sitename2"},
{ date:"2009-11-11", visitors:"282678", name:"Sitename2"},
{ date:"2009-11-12", visitors:"568754", name:"Sitename2"},
{ date:"2009-11-13", visitors:"695135", name:"Sitename2"},
{ date:"2009-11-14", visitors:"365874", name:"Sitename2"},
{ date:"2009-11-08", visitors:"552678", name:"Sitename3"}, // On this day, Sitename3 got 552678 visitors
{ date:"2009-11-09", visitors:"265875", name:"Sitename3"},
{ date:"2009-11-10", visitors:"452648", name:"Sitename3"},
{ date:"2009-11-11", visitors:"965875", name:"Sitename3"},
{ date:"2009-11-12", visitors:"695135", name:"Sitename3"},
{ date:"2009-11-14", visitors:"365898", name:"Sitename3"},
So I need to re-arrange (dynamically) [not sorting] the above ArrayCollection into:
{ date:"2009-11-08", Sitename1:252678, Sitename2:598754, Sitename3:552678},
{ date:"2009-11-09", Sitename1:655378, Sitename2:255378, Sitename3:265875},
{ date:"2009-11-10", Sitename1:452648, Sitename2:268554, Sitename3:452648},
This Data will be the dataProvider of an AreaChart, so the fastest way is generally the best way to go
Thanks allvar timeKeyed:Object = {}
for each (var datum:Object in arrayCollection) {
if (!(datum.date in timeKeyed)) {
timeKeyed[datum.date] = { date : datum.date };
timeKeyed[datum.date][datum.name] = datum.visitors;
var newCollection:ArrayCollection = new ArrayCollection();
for each (var datum:Object in timeKeyed) {
newCollection.addItem(datum);
You may need to sort newCollection when you're done. That's left as an exercise to the reader. -
Multiple ArrayCollection as DataProvider
Hi,
I've multiple source of XML which are saved as multiple
ArrayCollections in Flex. I've a single datagrid, which shows some
of the each ArrayCollection's elements in it. How could I
merge/throw those multiple ArrayCollection as DataProvider in the
datagrid?
Any help..?
ASBYou will need to concatenate the ArrayCollections into one,
as there is no way to specify multiple dataProviders for a single
control. This might be easier to do within XML (before wrapping it
in an ArrayCollection), depending on what your data looks
like. -
Qualification Information updated in PUI not reflected in Self Service
Hi there,
I noticed that when I update my qualification information via sefl service, after HR approval, this information is reflected in the Qualification forms in the PUI.
However, if I update my qualification via PUI, this information is not reflected in my self service page.
Im currently lost as to tracking why is this happening. Im not even able to locate the tables these information are written into.
Any clue would be great!
Thanks & cheers,
HKYou also might want to try myDataProvider.refresh(), where myDataProvider is the data provider for the DataGrid. Make sure you are using a collection like ArrayCollection or XMLListCollection and you are using the [Bindable] metadata tag.
If this post answers your question or helps, please mark it as such. Thanks!
http://www.chikaradev.com
Adobe Flex Development and Support Services -
Trying to scan photos from my photo album to a folder on my desktop. Have been trying to figure out for hours. Seems very complicated and cumbersome. Can anyone help? It's got to be much quicker (fewer key strokes) and simpler than what I've been able to discover.
Open the file, parse it, populate an ArrayCollection or XMLListCollection, and make the collection the DataGrid dataProvider:
http://livedocs.adobe.com/flex/3/html/help.html?content=Filesystem_08.html
http://livedocs.adobe.com/flex/3/html/help.html?content=12_Using_Regular_Expressions_01.ht ml
http://livedocs.adobe.com/flex/3/html/help.html?content=dpcontrols_6.html
http://livedocs.adobe.com/flex/3/langref/mx/collections/ArrayCollection.html
http://livedocs.adobe.com/flex/3/langref/mx/collections/XMLListCollection.html
If this post answered your question or helped, please mark it as such.
Maybe you are looking for
-
Receiving the internal 500 error while testing java web service
HI, Problem Summary: Receiving the internal 500 error while testing java web service in integrated weblogic server. my scenario is like, retrieve the Payload from Dehydration tables. We are connected to SOA_INFRA schema and we are retrieving the payl
-
How can i download a stand alone version of adobe reader 9.5.2 for windows XP
I can download the .msp for 9.5.2 but this will not install on Windows XP. I need to download a stand alone version for deployment to client machines. Please help.
-
Hi Gurus, Please suggest me a report where we can find material, material group, quantity purchased in a year, at what price, vendor. Please revert asap. Thank You
-
How can i get a UK Macbook delivered abroad?
Hello, I am interested in buying a macbook, preferably one accompanied with a UK keyboard. However, i am currently located at Greece, and i have seen that applestore does not ship products outside UK. Moreover, getting a macbook here is impossible si
-
I am scaning all old pictures, docts, slides ,but I have alot of b&w negs verious sizes, how can I turn them into b&w positives??