Вопрос

Trying to get my communities list(and profile as well) using javascript ibmsbt api passing object with load function to getMyCommunities function has no result. Function assigned to load property simply doesn't get executed. Here is the code:

var communityService = new CommunityService();
communityService.getMyCommunities({
    load: function(communities) {
        var ul = document.getElementById("communities")
        for (var i=0; i<communities.length; i++) {
            var community = communities[i];     
            var li = document.createElement("li");
            ul.appendChild(li);
            li.setAttribute("id", "community" + i);
            dom.setText("community" + i, community.getTitle());
        }
    },
    error: function(error) {
        console.error("Error: "+error.message);
    }
});

But when I'm using promises everything works like a charm. Here it is:

    var cp = communityService.getMyCommunities();
cp.then(
    function(communities){
        var ul = document.getElementById("communities")
        for (var i=0; i<communities.length; i++) {
            var community = communities[i];     
            var li = document.createElement("li");
            ul.appendChild(li);
            li.setAttribute("id", "community" + i);
            dom.setText("community" + i, community.getTitle());
            }
    },
    function(error){
        console.error("Error: " + error.message);
    });

API documentation on the part of load function says: This function is invoked when the call to get my communities completes. The function expects to receive one parameter, the communities object - an array of my communities. api doc

What am I missing?

Это было полезно?

Решение

our API documentation is out of date. We only support the Promise syntax for asynchronous calls. I'll get the API documentation updated but in the meantime you can use the documentation in the SDK download.

regards Mark

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top