jsTree Lazy Loading

687 views
Skip to first unread message

gray web

unread,
Sep 8, 2015, 12:42:19 PM9/8/15
to jsTree
Hi

I have been trying to implement the lazy loading of nodes for several days following the instructions in the downloaded README.

However, what I'm really struggling with is what happens at the server. The example code

```html
<div id="container"></div>
<script>
$(function() {
  $('#container').jstree({
    'core' : {
      'data' : {
        "url" : "//www.jstree.com/fiddle/?lazy",
        "data" : function (node) {
          return { "id" : node.id };
        }
      }
    }
  });
});
</script>

calls www.jstree.com/fiddle/?lazy  which, I presume, is a php file with an SQL Select statement in it that looks for children of the opening node and reformats the results in JSON format?? But I cannot find the source for it. Does anyone have that or can you provide similar?

Thanks

Ivan Bozhanov

unread,
Sep 9, 2015, 1:35:40 AM9/9/15
to jsTree

gray web

unread,
Sep 9, 2015, 5:04:15 AM9/9/15
to jsTree
Hi Ivan

As I am hosting on my local machine I presume I will have to edit the SQL connection parameters i.e database name and password.... where those parameters please? I found only the database name?

Thanks

gray web

unread,
Sep 9, 2015, 5:10:04 AM9/9/15
to jsTree
Hi Again

Sorry, I found this: 


/*
 // create instance protocol://user:pass@host/db?charset=UTF8&persist=TRUE&timezone=Europe/Sofia
 $db = DB::get('mysqli://ro...@127.0.0.1/test');
 $db = DB::get('oracle://root:pass@VIRT/?charset=AL32UTF8');
 // execute a non-resulting query (returns boolean true)
 $db->query('UPDATE table SET value = 1 WHERE id = ?', array(1));
 // get all results as array
 $db->all('SELECT * FROM table WHERE id = ?', array(1), "array_key", bool_skip_key, "assoc"/"num");
 // get one result
 $db->one('SELECT * FROM table WHERE id = ?', array(1), "assoc"/"num");
 // get a traversable object to pass to foreach, or use count(), or use direct access: [INDEX]
 $db->get('SELECT * FROM table WHERE id = ?', array(1), "assoc"/"num")[1];
 */





Are these instructions? Am I meant to uncomment them? And where do I add my password if I do please?

Thanks



On Wednesday, 9 September 2015 06:35:40 UTC+1, Ivan Bozhanov wrote:

gray web

unread,
Sep 9, 2015, 7:41:27 AM9/9/15
to jsTree
Hi

I have found it. For anyone else look in the class.db.php file in the demo/sitebrowser directory and look for the following reference:-

public $password

It appears to be set to null by default. I changed it and the tree fired up!

Thanks


On Wednesday, 9 September 2015 10:10:04 UTC+1, gray web wrote:
Hi Again

Sorry, I found this: 

/*
 // create instance protocol://user:pass@host/db?charset=UTF8&persist=TRUE&timezone=Europe/Sofia
 $db = DB::get('mysqli://root@127.0.0.1/test');

Ivan Bozhanov

unread,
Sep 9, 2015, 12:31:33 PM9/9/15
to jsTree
Do not set it in the class itself just modify the connection string found here:
https://github.com/vakata/jstree/blob/master/demo/sitebrowser/index.php#L6

From:
'mysqli://ro...@127.0.0.1/test'
To:
'mysqli://USERNAME:PASSWORD@SERVER/DATABASE'

Of course replace USERNAME, PASSWORD, SERVER and DATABASE with your values. Using such connection strings is pretty common. DO NOT modify the class code.

Best regards,
Ivan



gray web

unread,
Sep 9, 2015, 3:22:17 PM9/9/15
to jsTree
Ok thanks Ivan... it's working nicely!
Reply all
Reply to author
Forward
0 new messages