1

file snapshot_report_js.js:

require([
    "dojo/dom",
    "dojo/json",
    "dojo/store/Memory",
    "dijit/tree/ObjectStoreModel",
    "dijit/Tree",
    "dojo/text!http://localhost:8080/dojo/json_data/snapshot.json",
    "dojo/domReady!",
    "dojo/_base/json"
], function(dom, json, Memory, ObjectStoreModel, Tree, small){
    var stringfied_content = JSON.stringify(small)
    var json_parsed_data = JSON.parse(stringfied_content, true)
    var json_data = dojo.toJson(json_parsed_data);
    // set up the store to get the tree data
    var json_store = new Memory({
        data: [ json_data ],
        getChildren: function(object){
            return object.children || [];
        }
    });
    // Create the model
    var snapshot_treeModel = new ObjectStoreModel({
        store: json_store,
        query: {id: 'snapshot'}
    });

    var snapshot_tree = new dijit.Tree({
        model: snapshot_treeModel
    }, 'div_snapshot_tree');
    snapshot_tree.startup();  
})

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Snapshot</title>
<link rel="stylesheet" href="dijit/themes/claro/claro.css">
<!-- load Dojo -->
<script src="dojo/dojo.js" data-dojo-config="async: true"></script>
<script src="js/snapshot_report_js.js"></script>
</head>
<body class="claro">
<div id="div_snapshot_tree"></div>
</body>
</html>

JSON file:

{
    "snapshot_metadata": {
            "report_end_at": "2017-10-11 02:03:36", 
            "environment_name": "DVINST", 
            "report_start_at": "2017-10-11 01:55:42"
    },
    "versions": [
        {
            "id": "version_001",
            "instances": [
                {
                    "instance_name": "instance1", 
                    "instance_create_date": "2017-09-18 00:17:52", 
                    "connected_site_count": 4, 
                    "admin_server": "t3://tserver:18300", 
                    "instance_id": 2411, 
                    "instance_type": "OSVC", 
                    "instance_created_by": "None", 
                    "site_capacity": 2, 
                    "sites": [
                            {
                            "site_db_id": 395, 
                            "site_name": "zzzz_178", 
                            "site_users": "uc1,uc2,uc3", 
                            "site_id": 89492, 
                            "site_owner": "owner1", 
                            "site_db_name": "site_server2"
                            },
                            {
                            "site_db_id": 395, 
                            "site_name": "site2", 
                            "site_users": "u1, u2, u3", 
                            "site_id": 90447, 
                            "site_owner": "u2", 
                            "site_db_name": "site_server3"
                            }
                    ]
                }
            ]
        }
    ],
    "servers": [
        {
            "status": null, 
            "server_id": 13, 
            "server_name": "db1", 
            "server_type": "database", 
            "mount_points": [], 
            "sites": [], 
            "db_connections_count": 6, 
            "health": null, 
            "admin_servers": null, 
            "db_sites_connected_count": null
        }
    ]
}

Error on console:

dojo.js:8 Uncaught Error: dijit.tree.ObjectStoreModel: root query returned 0 items, but must return exactly one at Object.
(ObjectStoreModel.js.uncompressed.js:86) at dojo.js:8 at when
(dojo.js:8) at Object.getRoot
(ObjectStoreModel.js.uncompressed.js:82) at Object._load
(Tree.js.uncompressed.js:897) at Object.postCreate
(Tree.js.uncompressed.js:844) at Object.create
(_WidgetBase.js.uncompressed.js:453) at Object.postscript
(_WidgetBase.js.uncompressed.js:366) at new (dojo.js:8)
at snapshot_report_js.js:178

I don't see anything wrong here, can anybody help?

ADyson
  • 57,178
  • 14
  • 51
  • 63
user1767599
  • 47
  • 1
  • 6

1 Answers1

1

At first glance your ObjectStoreModel is trying to find root object for tree and as you specified it should have property id equals to snapshot; nothing in your JSON is matching that query.

Secondly, JSON data should bring tree-structured content while your JSON is unstructured; see ObjectStoreModel example how tree data looks like. If you have custom data structure then you need to transform it to be consumed by tree widget thru its model.

andy
  • 757
  • 5
  • 13