Sorry, I forgot to double-check I was
using the real method name. myArray.concat() will produce a shallow copy of
the array (meaning a new array that has the same contents).
Matt
From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Tracy Spratt
Sent: Friday, May 06, 2005 12:35
PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders]
Reloading Data Question
I guess "clone()" was psuedocode!
I just found "objectCopy" in the
livedocs flex api, and it is supposedly
"for internal use only".
But I also found Darron Schall's article about it
here:
http://www.darronschall.com/weblog/archives/000148.cfm
Also, for a simple array of objects, it is easy to
write your own copy
routine.
function arrayCopy(aArray:Array):Array {
var aCopy:Array = new Array()
for (var i:Number=0;i<aArray.length;i++)
{
aCopy.push(aArray[i]);
}
}
Tracy
-----Original Message-----
From: flexcoders@yahoogroups.com
[mailto:flexcoders@yahoogroups.com]
On
Behalf Of Manish Jethani
Sent: Friday, May 06, 2005 2:52 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Reloading Data Question
On 5/6/05, David Terry
<[EMAIL PROTECTED]> wrote:
> Or is it going to be some like...
> var objData:Object;
>
> objData = catalog.product.clone();
See this:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
xmlns="*">
<mx:Script>
import mx.utils.ObjectCopy;
function
copyObject(source:Object):Object
{
var
newObject:Object = ObjectCopy.copy(source);
ObjectCopy.copyProperties(newObject, source);
return newObject;
}
</mx:Script>
<mx:Model id="model">
<root>
<item>
<creature>elephant</creature>
<legs>4</legs>
</item>
<item>
<creature>human</creature>
<legs>2</legs>
</item>
</root>
</mx:Model>
<mx:DataGrid id="grid"
dataProvider="{copyObject(model.root).item}" />
<mx:Button
click="grid.removeItemAt(0)">
<mx:label>grid.removeItemAt(0)</mx:label>
</mx:Button>
<mx:DataGrid id="grid2"
dataProvider="{model.root.item}" />
</mx:Application>
copyObject() makes a copy of the object.
Clicking on the
"removeItemAt(0)" button removes the 1st
item from the first grid
only. So the original data provider object
(which the second grid
uses directly) is not modified.
Yahoo! Groups Links
Yahoo! Groups Links
|