0

I am struggling here. Using this simple pagination plug (http://flaviusmatis.github.io/simplePagination.js/#page-19) and trying to set the number of items to a value returned from an ajax call. But it will never work. If I set the number of items to a hard coded number it works just fine, but every for every letter I call this function with the number of items will change so I want to do it with this call.

This is what I have:

$(document).ready(function () {

        ko.applyBindings(viewModel);
        var numNames;

        $.ajax({
            type: "GET",
            url: "/api/Name/GetBoyCount?letter=" + viewModel.Letter(),
            complete: function (data) {
                $(selector).pagination('updateItems', parseInt(data));

            }
        });

        $(function () {
            $(selector).pagination({
                items: 100,
                itemsOnPage: 175,
                cssStyle: 'light-theme'
            });
        });

// etc
4

1 回答 1

2

您的 ajax 调用可能在初始化之前完成,请尝试将初始化代码从.ready()回调中取出。

改变这个

$(function(){
    $(selector).pagination({
        etc....
    });
});

到这个 $(selector).pagination({ etc.... });

$(document).ready(function(){})$(function(){}).ready()从另一个就绪检查内部调用相同。

于 2014-04-18T19:28:18.987 回答