- Nov 3, 2008You are missing the empty parenthesis at the end of getTreeDefinition,
it should be:
var tree_struct_x = tree.getTreeDefinition();
Without the parenthesis you are not assigning the tree definition to
tree_struct_x, which is what you want, but you are assigning it a
reference to the function, thus the alert is showing the string
representation of that function itself, which is its code. A JSON
string should not contain executable code and that is why stringify
refuses to convert it.
they can be referenced by variables. What you usually refer to as the
function is referred to by the name of the variable that is pointing to
it. As any other object, you can copy a reference to that instance of
the Function object (ie: the (lowercase) function) from one variable to
the next. The method toString of class Function renders the body of the
function. As you can see in your alert() below, there is no name as
part of the function since functions have no intrinsic names. The ()
operator, applied to an instance of a Function object, executes it.
var tree_struct_x = tree.getTreeDefinition;
See the parenthesis within the alert? The first statement copies a
reference to the function, not the result of executing it so
tree_struct_x now becomes a 'function' (actually, a new reference to the
same Function instance) which you can execute at any time by appending
the parenthesis to it. Anyway, this is not what you want to do, it was
just to prove the point. You simply put the parenthesis in the first
statement as shown above.
> On Nov 2, 2008, at 1:53 AM, Satyam wrote:
>> Cookies have to be strings or things that have string representations.
>> The string representation of an object is "[object]"which is not very
>> You have to use the JSON utility to convert the tree definition to a
>> string and store that string into the cookie. On the way back, you
>> the cookie, parse it with the JSON utility and use that as the second
>> argument to the TreeView constructor.
> Thanks again :) I had also tried that but this is the result:
> All of this is in <head> along with the treeview and cookie .js's:
> var tree_struct_x = tree.getTreeDefinition;
> var tree_data_string_x =
> 1st alert is:
> function ()
> return this.getRoot().getNodeDefinition();
> 2nd one is:
> Seems om as per: http://developer.yahoo.com/yui/json/#stringify
> What am I doing wrong ?
> Yahoo! Groups Links
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com
> Version: 8.0.175 / Virus Database: 270.8.5/1762 - Release Date: 02/11/2008 9:51
- << Previous post in topic Next post in topic >>