开发者

How to set id after creating new jstree node?

I'm using jsTree 1.0. And have this code :

$(document).ready(function () {
    $("#folders_tree").jstree({
        "core": {
            "initially_open": ["root"]
        }, "html_data": {
            "data": '<?= $folders; ?>'
        }, "themes": {
            "theme": "default",
            "dots": true,
            "icons": true,
            "url": "<?= Yii::app()->request->baseUrl ?>/css/jstree/themes/default/style.css"
        }, "contextmenu": {
            "items": {
                "create": {
                    "label": "Create",
                    "action": function (obj) {
                        this.create(obj);
                    }, "_disabled": false,
                    "_class": "add",
                    "s开发者_如何学编程eparator_before": false,
                    "separator_after": false,
                    "icon": false
                }, "rename": {
                    "label": "Rename",
                    "action": function (obj) {
                        this.rename(obj);
                    }, "_disabled": false,
                    "_class": "rename",
                    "separator_before": false,
                    "separator_after": false,
                    "icon": false
                }, "remove": {
                    "label": "Delete",
                    "action": function (obj) {
                        this.remove(obj);
                    }, "_disabled": false,
                    "_class": "delete",
                    "separator_before": true,
                    "separator_after": false,
                    "icon": false
                }, "ccp": false
            }
        },

        "plugins": ["themes", "html_data", "ui", "crrm", "contextmenu"]
    });

    /* Callbacks */

    var folders = $("#folders_tree");

    folders.bind("create.jstree", function (e, data) {
        var parent_id = data.rslt.parent[0].id;
        var name = data.rslt.name;
        var node = data.args[0];
        var dataArray = {
            "ref_folder": parent_id,
            "name": name
        };
        var dataString = JSON.stringify(dataArray);
        $.ajax({
            type: 'POST',
            url: '<?= Yii::app()->createUrl('
            ajax / createfolder ') ?>',
            data: {
                data: dataString
            }, success: function (jdata) {
                var json_data = JSON.parse(jdata);
                // Here's! This code is not working. Id is not set.
                $(node).attr("id", json_data.new_id);
            }, dataType: 'text'
        });
    });
});    

$(node).attr("id", json_data.new_id) // this code is not working.

I'm stuck on this :( How can I set this id?


The node variable must be declared as :

var node = data.rslt.obj;

And called as :

node.attr("id", json_data.new_id);


I would do alert(jdata) in the success callback.

Be sure the server is returning safe JSON and that the actual new_id attribute exists.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜