2

I am generating a tree in plone using an add-on product called collective.virtualtreecategories . However, I keep getting a weird javascript error and the tree cannot be displayed.

On my browser's error console, I get the following:

$tree.tree is not a function

Here is the part of code that produces the error:

$tree.tree({
    data: {
        type: "json",
        url: "@@vtc-categories-tree.json",
        async: false
    },
    lang: {
        new_node: "New category"
    },
    rules: {
        deletable: ["folder"],
        renameable: ["folder"],
        draggable: "none",
        droppable: "none",
    },
    callback: {
        beforechange: function(node, tree_obj) {
            return before_change_node()
        },
        onselect: function(node, tree_obj) {
            node_selected(node)
        },
        oncreate: function(node) {
            jq(node).attr('rel', 'folder')
        },
        onrename: function(node, lang, tree_obj, rb) {
            old_id = node.id // may be undefined (new node)
            new_name = jq(node).children("a:visible").text();
            // shared code. Server determines if creating/renaming by the old_name value
            jq.ajax({
                type: 'POST',
                url: "vtc-category-added-renamed",
                data: {
                    'category_path': selected_category(node),
                    'old_id': old_id,
                    'new_name': new_name
                },
                success: function(data) {
                    jq.jGrowl(data.msg, {
                        life: 1500
                    });
                    // set/change node id
                    if (data.result) {
                        node.id = data.new_id
                    }
                },
                dataType: 'json',
                traditional: true
            })
        },
        beforedelete: function(node, tree_obj) {
            jq.ajax({
                type: 'POST',
                url: "vtc-category-removed",
                data: {
                    'category_path': selected_category(node)
                },
                success: function(data) {
                    jq.jGrowl(data.msg, {
                        life: 3000
                    });
                },
                dataType: 'json',
                traditional: true
            });
            return true;
        }
    }
});​

The complete code listing can be found HERE

Can someone help me fix this?

UPDATE: I should perhaps add that, this was working before in a different setting. Now, I just recreated the project and thats when I got this error.

Frankline
  • 40,277
  • 8
  • 44
  • 75
  • 2
    Did you include a jQuery "tree" plugin? *Before* running this script? – cHao Oct 03 '12 at 13:06
  • 1
    what sort of object is $tree? The problem is as the message suggests that `$tree` doesn't have a function `tree` on it. This suggests that $tree is not the object you think it is or that you are not calling something you should be further up. So examine `$tree` to find out what it is and make sure it definitely should have a `tree` function on it. – Chris Oct 03 '12 at 13:08
  • @Chris: According to the link, `$tree` is a jQuery object. – cHao Oct 03 '12 at 13:09
  • @cHao: true enough. So yeah, the problem is that nothing has defined that function on the jQuery object by the looks of things. I guess that is what the "tree plugin" you mentioned would be expected to do. – Chris Oct 03 '12 at 13:12

3 Answers3

0

As far as I can tell from your code $tree isn't a function, its an element on line 89 var $tree = jq('ul#VTCTree');

therefore I assume .tree() is a JQuery widget and isn't working as expected?

Just seen some of the comments and the updates. Have you checked the path/file inclusion of the tree plugin/widget?

Jon Wells
  • 4,191
  • 9
  • 40
  • 69
  • @Frankline have you got a link to the plugin? – Jon Wells Oct 03 '12 at 13:23
  • Yes, I have included it on my question below the code. This is how it should look like: [Plugin Product](http://plone.org/products/collective.virtualtreecategories/) – Frankline Oct 03 '12 at 13:29
0

On my browser's error console, I get the following:

if your browser is Internet Explorer, the extra comma that you have here

droppable: "none",

is a widely known problem.

Not a problem for Firefox, but will give unexpected results, like 3 elements in the following array. but length = 4

myArr = [1,2,3,,]

also, check this https://stackoverflow.com/a/5139232/982924

Community
  • 1
  • 1
RASG
  • 5,988
  • 4
  • 26
  • 47
0

I had the same issue, even though I had jquery loaded and the jquery.filetree.min plugin loaded. I was missing the jquery UI js which is also required.

John J Smith
  • 11,435
  • 9
  • 53
  • 72