loads data to the component via XML or JSON, usually component config
data | string|object | XML|JSON URL|string|object |
doOnLoad | function | (optional) calls user-defined handler after data is loaded and rendered |
promise | a "promise" object |
var myComponent = new dhtmlXComponent();
// local json/xml object
myComponent.loadStruct({data:[{id:"a1",..},{id:"a2",..}]});
// local json/xml string
myComponent.loadStruct('<data><node id="a1".../></data>');
// json/xml from server
myComponent.loadStruct("server/data.xml");
// local json/xml with callback
myComponent.loadStruct({data:[{id:"a1",..},{id:"a2",..}]}, function(){
// data loaded and rendered
// your code here
});
// local json/xml string with callback
myComponent.loadStruct('<data><node id="a1".../></data>', function(){
// data loaded and rendered
// your code here
});
// json/xml from server with callback
myComponent.loadStruct("server/data.xml", function(){
// data loaded and rendered
// your code here
});
// returns a "promise" object, see details
myComponent.loadStruct(url).then(function(text){
// text - a server side response
});
The type of incoming data will be detected automatically, so you can use this method for loading both XML and JSON in different formats:string, URL from server, object itself.
In the case of loading config from server:
DHTMLX is integrated with Promiz.js library to treat the result of asynchronous operations (like data loading) without callbacks. Read more about integration of DHTMLX with Promiz.js.