回调不起作用

时间:2013-03-22 23:27:59

标签: javascript jquery callback

我最近一直困惑于为什么我的代码无效。我已经尝试将回调调用放在不同的地方,似乎没有任何工作。 我的代码在这里:

function initializeGallery(callback) {
    getAllEntriesOfDirectory("projects", function (directories) {
        var i = 1;
        for (var i = 1; i < directories.length; i++) {
            var id = directories[i].name;
            $("#bigSlider").append(
                "<div class='swiper-slide'><div class='m-content' id='m-content-" + id + "' style='background-size: cover;height: 100%; background-position: center; background-color:white;'><div class='m-center'><h3>" + id + "</h3><p>Last Edited .<br/>Created</p><div data-role='controlgroup' data-type='horizontal' ><a href='editor.html?id=" + id + "' data-role='button' data-icon='forward' data-mini='true' data-iconpos='notext' rel='external'>Open</a><a href='fullscreen.html?id=" + id + "' data-role='button' data-icon='search' data-mini='true' data-iconpos='notext' rel='external'>View</a><a href='#deletePopup' data-role='button' data-rel='popup' data-icon='minus' data-mini='true' data-iconpos='notext'>Delete</a></div></div></div></div>"
            ).ready(function () {
                readText("projects/" + id + "/painting.txt", function (data) {
                    $("#m-content-" + id).css("background-image", "url('" + data + "')");
                    $("#littleSlider").append("<img style='background: white;' src='" + data + "'> ");
                });
            });
            if (i == directories.length - 1) callback();
        }
    });
}

以下是我调用initializeGallery函数的代码:

initializeGallery(function () {
    swiperMovies.reInit();
    swiperMControl.reInit();
    $('.mc-control img').bind('mousedown', function (e) {
        e.preventDefault()
    });
    $('.mc-control img').bind('click', function (e) {
        e.preventDefault()
        if (!allowMovieClick) return;
        var index = $(this).index()
        swiperMovies.swipeTo(index)
        $('.mc-control .active').removeClass('active')
        $(this).addClass('active')
    });
    $(".mc-device").trigger('create');
    $.mobile.hidePageLoadingMsg();
});

由于某种原因,只有最后一张图片似乎被加载到页面中。我认为这是一个回调问题。有什么想法吗?

0 个答案:

没有答案