<script>
require([
"dojo/request/xhr",
"dijit/tree/ObjectStoreModel",
"dojo/store/Memory",
"dijit/Tree",
"dojo/domReady!"
],
function(xhr, ObjectStoreModel, Memory, Tree){
var xhrArgs = {
method:"POST",
data: 'query={DATA:{},COMMAND:"GETSTAFFVIEW"}',
handleAs: "json"
}
// Call the asynchronous xhrPost
var def = xhr("viewQueryManager", xhrArgs);
def.then(function(data){
alert("AjaxTrue");
createStaffView(data);
}, function () {
alert("AjaxError");
})
function createStaffView(staffData){
// Create test store, adding the getChildren() method required by ObjectStoreModel
var myStore = new Memory({
data: staffData,
getChildren: function(object){
return this.query({parent: object.id});
}
});
// Create the model
var myModel = new ObjectStoreModel({
store: myStore,
query: {id: 0}
});
// Create the Tree.
var tree = new Tree({
model: myModel
});
tree.placeAt("staffTree");
tree.startup();
}
});
</script> |