TARKUS
TARKUS

Reputation: 2200

jQueryFileTree How to clear instance, reinstantiate new instance or refresh

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.

Upvotes: 0

Views: 692

Answers (1)

ixM
ixM

Reputation: 1264

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.

Upvotes: 1

Related Questions