Load data from a property of the result object in Webix

1.2k Views Asked by At

I have a Webix list and want to load data dynamically. The problem is that the data is under the results.entries key in the JSON object returned by the AJAX call. How should I load that data?

So far what I came up with is slightly convoluted:

var result = webix.ajax().sync().get('/my-rest-endpoint');
$$('mylist').parse(JSON.parse(result.responseText).results.entries);
1

There are 1 best solutions below

0
On

With sync() method, callback is synchronous. But I recomended to you if your '/my-rest-endpoint' has a waiting time to be generated, use ajax async() method, like this example

webix.ajax().get('/my-rest-endpoint',{
    // Error callback
    error:function(text, data, XmlHttpRequest){
        alert("error");
    },

    //Success callback
    success:function(text, data, XmlHttpRequest){
        var data = JSON.parse(text);
        $$('mylist').parse(data.results.entries);
    }
});

Regards