1

嘿专家我想将jqpaginations集成到我的一个android phonegap项目中,在前面使用jquery mobile ui,现在我面临的问题是我是jquery的新手,所以我无法集成它,我得到的记录从 json 返回,我可以使用 .length 计算记录,但现在我想将它们分开,假设它们是 20,所以应该有 4 页,每页有 5 条记录..

http://devlegallogs.logisticslogic.com/AppCode/MyTasks.html

这是我的项目和 fyi 的链接,我没有使用 ul li 而是为每条记录重复一个 div ......

请帮助我浪费了我的一天......

已编辑:我已经在某种程度上做到了,但仍然存在问题,当我前进时,它工作正常,但是当我返回时它显示了两次记录,我知道这是我的代码问题,但如何解决我被绞死了!

这是代码片段,我正在提交成功函数中的代码:

var dd = 数据;var ObjUl = $(''); var ObAccord = $('');

                             $(".pagination").hide();
                                var recordsPerPage = 5
                                var totalNumRecords = data.length;
                                //alert(totalNumRecords);

                                if (recordsPerPage < totalNumRecords) {
                                     pagination(recordsPerPage, totalNumRecords);
                                }



                                //recordsPerPage is the number of items you want to display on each page
                                //totalNumRecords is the total number of items that you have

                                function pagination(recordsPerPage, totalNumRecords){
                                    //Show the pagination controls
                                    $(".pagination").show();

                                    //loop through all of the divs and hide them by default.
                                    for (var i=1; i <= totalNumRecords; i++) {   
                                        $("#mydiv").find("#set" + i).hide();
                                    }

                                    //then only display the number of divs the user dictated
                                    for (var i = 1; i <= recordsPerPage; i++) {

                                          var dueDate = data[i]['due_date'];
                                          var title = data[i]['title'];
                                          var descr = data[i]['description'];
                                          var recId = data[i]['id'];
                                          var sendcount=i;
                                          var ObjMya = buildAccordianTaskListItem(dueDate, title, descr, recId,sendcount);
                                            ObAccord.append(ObjMya);

                                        $("#mydiv").find("#set" + i).show();
                                    }

                                    //maxPages is the maximum amount of pages needed for pagination. (round up) 
                                    var maxPages = Math.ceil(totalNumRecords/recordsPerPage);   

                                    $('.pagination').jqPagination({
                                        link_string : '/?page={page_number}',
                                        max_page     : maxPages,
                                        paged        : function(page) { 
                                            //alert(page);
                                            //a new page has been requested
                                            alert('paged');
                                            //loop through all of the divs and hide them all.
                                            for (var i=1; i <= totalNumRecords; i++) {
                                                $("#mydiv").find("#set" + i).hide();
                                                //alert('upper');
                                            }

                                            //Find the range of the records for the page: 
                                                var recordsFrom = recordsPerPage * (page-1) + 1;
                                            var recordsTo = recordsPerPage * (page);

                                            //then display only the records on the specified page
                                            for (var i = recordsFrom; i <= recordsTo; i++) {
                                               // alert('lower');
                                               // alert(recordsTo);
                                                var dueDate = data[i]['due_date'];
                                                var title = data[i]['title'];
                                                var descr = data[i]['description'];
                                                var recId = data[i]['id'];
                                                var sendcount=i;
                                                var ObjMya = buildAccordianTaskListItem(dueDate, title, descr, recId,sendcount);
                                                ObAccord.append(ObjMya);

                                               $("#mydiv").find("#set" + i).show();
                                                //var $list = $('#mydiv');

                                            }      
                                           // $list.trigger('create');
                                            //$list.listview('refresh');
                                            //scroll to the top of the page if the page is changed
                                            $("html, body").animate({ scrollTop: 0 }, "slow");
                                        }
                                    });
                                }




            $('#mydiv').append(ObjUl);
            $('#mydiv').append(ObAccord);

            $(".myaccClass").click(function (e) {
                $('.accorddesc').hide();
                $('.ui-icon').attr('class', 'ui-icon-plus ui-icon ui-icon-shadow');
                $('.accorddesc', this).toggle('ui-collapsible-content ui-body-a');
                $('.ui-icon', this).toggleClass("ui-icon-minus");
            });
4

0 回答 0