[sf-perl] OffTopic: Any JavaScript programmers here?
yary
not.com at gmail.com
Fri Jul 4 19:25:06 PDT 2008
Keeping this on-list since it's also a general coding question. I
think the issue is shallow vs deep copying an object. When you have a
line like
var theList = document.getElementById(ListHandle);
then theList is a handle into the list as a whole, and if the elements
change order in the document, then they change in theList as well.
What you need is called a "deep copy", where you walk through the
object's elements/attributes, and copy all those as well.
In general you need to think about how to copy each element as well-
do you want to deep copy recursively all the way down? In this
example, we might, if you're sorting the sublists as well. And we can
get a deep copy by freezing a string copy-
var origList = theList.innerHTML; // a way in perl: use Storable,
$origList = freeze \@theList;
to set it back
theList.innerHTML = origList; // in perl, @theList = @{ thaw $origList };
I assume you're still working on this page, as the "sort these" links
are currently out of order- I'll recommend using firebug in ff while
debugging, though there are other page insepection/js debug tools and
if you have one you like stick with it.
More information about the SanFrancisco-pm
mailing list