代码之家  ›  专栏  ›  技术社区  ›  mvark

使用jQuery模板插件和分页插件在客户端分页时显示动态生成的记录时出现问题

  •  0
  • mvark  · 技术社区  · 14 年前

    Microsoft's jQuery Templates plugin 伴随着 G Birke's jQuery Pagination plugin . 我本可以只使用分页插件来管理,但现在肯定需要模板插件来保存在服务器端生成格式化记录所涉及的处理。

    my code sample on JSBin ( see source ). 此示例是对 Stephen Walther's Templates plugin example Pagination plugin example 通过 StackOverflow member brianpeiris

    $("#flickr").live("click", function() {
        var url = "http://api.flickr.com/services/feeds/groups_pool.gne?id=44124373027@N01&lang=en-us&format=json&jsoncallback=?";
            // Grab some flickr images of cats
            $.getJSON(url, function (data) {
                // Format the data using the catTemplate template
                $("#catTemplate").tmpl(data.items).appendTo("#hiddenresult");
            });
        alert("Total flickr records fetched =" + $('#hiddenresult div.result').length);
        initPagination();
    
     });
    

    1. 只有在出现上述代码中的警报时,才会在Firefox&IE8中通过分页显示记录。警报可能会导致延迟。如何修复代码,使其在没有警报的情况下工作?
    2. 即使存在警报,该示例在Chrome、Safari&Opera中也不起作用。如何使解决方案跨浏览器?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Chris Westbrook    14 年前

    我想您需要将initPagination()函数调用移到getjson函数的回调函数中,然后将模板附加到dom。