jQuery mobile:等到$ .getJSON完成

bij*_*jin 0 jquery json asynchronous jquery-callback jquery-mobile

我想通过$.getJSON调用填充表格:

$.getJSON("localhost/url",
function (data) {
    $.each(data.reporting_list.reporting, function (i, item) {
        rows = '<tr><td>' + item.data1 + '</td><td>' + item.data2 + '</td></tr>'
    });
    $('#aaa').append(rows);
});
Run Code Online (Sandbox Code Playgroud)

填充后我想激活一些页面更改:

$.mobile.changePage("#homePage");
Run Code Online (Sandbox Code Playgroud)

但页面在$.getJSON完成之前发生了变化.
我想在$.getJSON完成后更改页面并改为显示ajaxloader.

Aru*_*hny 7

$.getJSON("localhost/url", function (data) {
    $.each(data.reporting_list.reporting, function (i, item) {
        rows = '<tr><td>' + item.data1 + '</td><td>' + item.data2 + '</td></tr>'
    });
    $('#aaa').append(rows);
    //move to the page in the callback itself
    $.mobile.changePage("#homePage");    
});
Run Code Online (Sandbox Code Playgroud)