Search Support
-
Radek SulcJune 9, 2016 at 4:15 am #2093
Hi there,
does SPARK UI tootlkit provide some simply callable function to clone an object and array of objects?
Why? For example ${Table}.appendElement() and appendElements{} add objects/rows to the table by reference what is not always what we need. We need to add clones to the table.
Any hints, different approach are welcome.
Thanks,
Radek
SPARK SupportJune 9, 2016 at 11:43 am #2097Radek,
One way I know of to do this, is to construct the JSON before appending to the table. For example, if you have a table with columns bound to parameters called, “str1” and “str2”, and the row needs to be populated from two text fields, you could do something like this:
${Table1}.appendElement({str1: ${Text1}.getData(), str2: ${Text2}.getData()});
This is not the most elegant solution, I’m inquiring about something more robust, but wanted to reply to you in the mean time.
Radek SulcJune 9, 2016 at 11:58 pm #2100The “best” way for potentially deep clone I have found so far is using JSON.parse(JSON.stringify(x)). It is not perfect from performance perspective but… I definitely need copy the whole object in one shot, not coding assignments at attributes level.
${InvolvedDepartmentsTable}.appendElements( JSON.parse(JSON.stringify( ${AddDepartmentsTable}.getSelectedRecords() )) );
This works for one object and for arrays/lists as well.
ElliotJune 14, 2016 at 1:10 pm #2136Thanks for that different approach Radek. That is a very clever way to do it when dealing with complex data objects.
-Elliot P.
-
|
You must be logged in to reply to this topic.