I have kept a unique ID for each of my listnodes <li> (e.g. ID="1", ID="2"...)and when I refresh the tree all the nodes are closed somehow.
<html><head> <link rel="stylesheet" href="./dist/themes/default/style.css" /> <script type="text/javascript" src="./dist/libs/jquery.js"></script> <script type="text/javascript" src="./dist/jstree.js"></script>
<script type="text/javascript"> jQuery(function() { jQuery('div#treeview').jstree({ 'core' : { "multiple" : false, "animation" : 100, 'data' : { 'url' : '/cgi-bin/..../dispatcher.cgi', 'data' : function (node) { return { 'id' : node.id }; } } } }); }) </script>
</head><body> <a href="#" onclick="jQuery('div#treeview').jstree().refresh()">refresh</a><br/><br/> <div id="treeview"> </div></body></html>use JSON;
sub load_node_test { my ($self, %par) = @_;
my ($id, $debug) = @par{'id','debug'}; my @entries ; my $parent = $id; my $entry_id = $id * 1 + 1; my %entry = ( id => $entry_id, parent => $parent, text => $entry_id, ); my $child_lr = []; if ( $id eq '#' ) { $child_lr = $self->load_node_test( id => $entry_id ); $entry{state}{opened} = JSON::true; } else { $entry{children} = JSON::true; }
push @entries, \%entry, @$child_lr; return \@entries;}| Content-Type | : application/json;charset=utf-8 |
[{"parent":"#","text":1,"id":1,"state":{"opened":true}},{"parent":1,"text":2,"children":true,"id":2}]
Opening folder 2 does return folder 3:[{"parent":"2","text":3,"children":true,"id":3}]
Opening folder 3 does return folder 4:[{"parent":"3","text":4,"children":true,"id":4}]
If I now click the refresh link, folder 1, 2 and 3 are loaded, but 3 is not opened. Folder 4 is missing.
If I open more than 4 folders, the refresh result will be the same: Only folders 1, 2 and 3 are displayed.
Here is the response of the refresh after opening folder 3:Request 1:
[{"parent":"#","text":1,"id":1,"state":{"opened":true}},{"parent":1,"text":2,"children":true,"id":2}]
Request 2:[{"parent":"2","text":3,"children":true,"id":3}]
I hope this helps to find the problem.
Regards,
Gert
[{"text":1,"children":true,"id":1}]
[{"text":2,"children":true,"id":2}]
Request 3 (Open folder 2):[{"text":3,"children":true,"id":3}]
Request 4 (Open folder 3):
[{"text":4,"children":true,"id":4}]
Refreshing the treeview:
Request 1:[{"text":1,"children":true,"id":1}]
Request 2:[{"text":2,"children":true,"id":2}]
=> Folder 3 (opened) and 4 (closed) are missing.
Greetings,GertCould you setup a demo somewhere?
#!/usr/bin/perl
use CGI;use strict;use JSON;
main: { my $cgi = CGI->new(); my $id = $cgi->param('id');
print "Content-Type: application/json;charset=utf-8\n\n";
my $entries_lr = load_node_test( id => $id );
my $json = JSON->new(); my $rc = $json->encode($entries_lr);
print $rc;}
sub load_node_test { my (%par) = @_;
my ($id, $debug) = @par{'id','debug'};
$id =~ s!^n!!;
my $entry_id = $id * 1 + 1;
$entry_id = 'n' . $entry_id;
my %entry = ( id => $entry_id, text => $entry_id, children => JSON::true, );
return [\%entry];}
I believe I told you to get the latest copy didn't I?
it would over complicate things I believe.