0

I'm using jQuery FileTree. After a file upload via javascript ajax (old school javascript xmlhttp request, not jQuery), I invoke the fileTree using the following code:

$('#jstree').fileTree({
            script: '/ajax/file_tree2/' + path,
            multiFolder: true,
            expandSpeed: 250,
            collapseSpeed: 250
        });

...which produces a nice graphic file tree that I can click around in (the path variable is the new folder, being used as a URI segment variable, and I've simply copied the server-side connector jQueryFileTree.php code into a public function in a CodeIgniter controller class. This is extra information that I don't think has anything to do with the problem, just FYI).

But, for some reason when I make a second call by uploading a new file (without having to reload the page), the file tree doesn't update or refresh. I want to refresh the tree structure when I upload new files for different folders.

I've tried to clear the #jstree element itself, using a loader gif:

$('#jstree').html('<img src=\"'+$("#base_url").html()+'/assets_/images/loading/loading36.gif\" />');

...or even just clearing the html:

$('#jstree').html('');

I've tried commands that are part of other widget-type libraries, like 'destroy' or 'refresh':

$('#jstree').fileTree.destroy();

$('#jstree').fileTree({
            refresh: true,
            script: '/ajax/file_tree2/' + path,
            multiFolder: true,
            expandSpeed: 250,
            collapseSpeed: 250
        });

These either do nothing or return a js error.

TARKUS
  • 2,170
  • 5
  • 34
  • 52

1 Answers1

1

I downloaded the raw source of v2.1.4 (467904a3ab5c13df094ffe01ddb0d0fea24c5d6a) and modified line 203 from:

if (!data) {

to

if (!data || (Object.prototype.toString.call(args) === '[object Object]' && args.reload)) {

Now, if I want to reload the fileTree, I just pass "reload: true" in the arguments array.

ixM
  • 1,244
  • 14
  • 29
  • I'm still on this project, so let me test this answer before marking as chosen answer. – TARKUS Nov 15 '16 at 18:28
  • Hopefully it'll help you. I am no JS guru so there might be a better way to do this but for me it served its purpose :) – ixM Nov 15 '16 at 20:43