php - 创建新的jstree节点后如何设置id?

标签 php jquery json jstree

我正在使用 jsTree 1.0。并有这个代码:

$(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",
                    "separator_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.

我卡在了这个 :( 我该如何设置这个 id?

最佳答案

节点变量必须声明为:

var node = data.rslt.obj;

并称为:

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

关于php - 创建新的jstree节点后如何设置id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3179491/

相关文章:

php - PDO fetch 什么都不返回

php - 用户按下注销并销毁 session 后,如何禁用后退浏览器按钮?

javascript - 如何一起使用 getElementById 和 getElementsByTagName 获取元素的值

jquery - 当用户滚动过去或低于特定的 div 时更改 css

javascript - 为什么 d3.json 返回 "null"?

php - 在 Linux 上从控制台运行脚本

php - 将 SQL 中的数据存储在数组中

javascript - 方法在点击事件上多次触发

json - 从组件中的Service解析JSON数组对象

java - jackson View 中的 DEFAULT_VIEW_INCLUSION 设置有问题