json 对象的 Dynatree 树视图 jquery 插件问题

Dynatree tree view jquery plugin issue with json object

js 文件中,dynatree 在节点中显示 null,因为它在 php 文件中工作正常。

        var jsoncat =  jsoncat.replace(/\%/g,'"').trim();
        var jsoncat =  '{"data":['+JSON.stringify(jsoncat)+']}';
        var jsonObj =  JSON.parse(jsoncat);

        var delay=1000;//1 seconds
        alert(typeof(jsonObj));
        alert(jsonObj.data);    

        setTimeout(function(){
            var treeData = [jsonObj.data];
                // --- Initialize sample trees
                jQuery('#tree1').dynatree({
                    checkbox: true,`enter code here`

                    // Override class name for checkbox icon:
                    classNames: {checkbox: "dynatree-radio"},
                    selectMode: 3,
                    children: treeData,
                    onActivate: function(node) {
                        jQuery('#echoActive1').text(node.data.key);
                    },

                    onSelect: function(select, node) {
                        // Display list of selected nodes
                        jQuery("#categoryid").val(node.data.key);
                    },

                    onDblClick: function(node, event) {
                        node.toggleSelect();
                    },

                    onKeydown: function(node, event) {
                        if( event.which == 32 ) {
                            node.toggleSelect();
                            return false;
                        }
                    },

                }); 
            },delay);

我的 JSON 格式不正确,一旦我得到正确的 JSON,我的问题 resolved.Here 是最新代码。

 str_trim = jsoncat.replace(/'/g,'"').trim();
            str = '{"data":['+str_trim+']}'
            var jsonObj =  JSON.parse(str);
            cWindowShow('jax.call("community","admin,groups,ajaxEditGroup", ' + groupId + ');', 'Editing Group' , 550 , 450);
            var delay=1000;//1 seconds
            setTimeout(function(){
                var treeData = jsonObj.data;
                    // --- Initialize sample trees
                    jQuery('#tree1').dynatree({
                        checkbox: true,
                        // Override class name for checkbox icon:
                        classNames: {checkbox: "dynatree-radio"},
                        selectMode: 1,
                        children: treeData,
                        onActivate: function(node) {
                            jQuery('#echoActive1').text(node.data.key);
                        },
                        onSelect: function(select, node) {
                            // Display list of selected nodes
                            jQuery("#categoryid").val(node.data.key);
                        },
                        onDblClick: function(node, event) {
                            node.toggleSelect();
                        },
                        onKeydown: function(node, event) {
                            if( event.which == 32 ) {
                                node.toggleSelect();
                                return false;
                            }
                        },

                    }); 
                },delay);