ezraroi / ngJsTree

Angular Directive for the famous JS Tree
http://ezraroi.github.io/ngJsTree/
MIT License
270 stars 98 forks source link

When create new node with contextmenu model of tree can't updated. #85

Closed ridvanenis closed 8 years ago

ridvanenis commented 8 years ago

Hi I use contextmenu plugin. I create new node with context menu create option. New node is adding in tree but model of tree can't update.

Here my tree config:

$scope.treeConfig = {
    core: {
        multiple: false,
        animation: true,
        error: function (error) {
            $log.error('treeCtrl: error from js tree - ' + angular.toJson(error));
        },
        data:$scope.treeData,
        check_callback: true,
        worker: true
    },
    types: {
        default: {
            icon: 'glyphicon glyphicon-paperclip'
        },
        star: {
            icon: 'glyphicon glyphicon-star'
        },
        cloud: {
            icon: 'glyphicon glyphicon-cloud'
        }
    },
    version: 1,
    plugins: ['contextmenu', 'search', 'types'],
    contextmenu: {
        items: function (o, cb) { // Could be an object directly
            return {
                create: {
                    separator_before: false,
                    separator_after: true,
                    _disabled: false, //(this.check("create_node", data.reference, {}, "last")),
                    label: "Ekle",
                    action: function (data) {
                        var inst = $.jstree.reference(data.reference),
                                obj = inst.get_node(data.reference);
                        inst.create_node(obj, {}, "last", function (new_node) {
                            setTimeout(function () {
                                inst.edit(new_node);
                            }, 0);
                        });
                    }
                },
                rename: {
                    separator_before: false,
                    separator_after: false,
                    _disabled: false, //(this.check("rename_node", data.reference, this.get_parent(data.reference), "")),
                    label: "Güncelle",
                    icon: "glyphicon glyphicon-leaf",
                    /*!
                     "shortcut"         : 113,
                     "shortcut_label"   : 'F2',
                     "icon"             : "glyphicon glyphicon-leaf",
                     */
                    action: function (data) {
                        var inst = $.jstree.reference(data.reference),
                                obj = inst.get_node(data.reference);
                        inst.edit(obj);
                    }
                },
                remove: {
                    separator_before: false,
                    icon: false,
                    separator_after: false,
                    _disabled: false, //(this.check("delete_node", data.reference, this.get_parent(data.reference), "")),
                    label: "Sil",
                    action: function (data) {
                        var inst = $.jstree.reference(data.reference),
                                obj = inst.get_node(data.reference);
                        if (inst.is_selected(obj)) {
                            inst.delete_node(inst.get_selected());
                        } else {
                            inst.delete_node(obj);
                        }
                    }
                }
            };
        }
    }
};
ezraroi commented 8 years ago

You are using it in the wrong way... The point of the directive is to provide way binding.. you need to add the node to the nodes array.. the tree will update automatically

Check the demo page code to see how to ad nodes