开发者

Appcelerator. Get data from request out of onload function

I am working with Appcelerator Titanium and I am making requests to a remote API. I need to get the results of a request out of the onload function and into another calling function. The request call is located in a function of its own in another file that is included in the main .js file.

This is my code: http:/开发者_开发问答/pastie.org/1731674

How can it be altered to do this?


Modify loadPhones() to accept a callback that accepts the output as a parameter

function loadPhones( callback ) {

    (...)

    xhr.onload = function() {

        (...)

        if ( 'function' == typeof callback ) {
            callback(output);
        }
    }

    (...)
}

And then, in app.js or wherever you call loadPhones() from

loadPhones( function( data ) {

    // do whatever with data

});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜