/**
 *
 * @author     ganxun
 * @version    1.0
 * @desc
 *
 */

sumeru.router.add({
    pattern    :   '/publishbypage',
    action  :   'App.publishByPage'
});

sumeru.router.setDefault('App.publishByPage');

App.publishByPage = sumeru.controller.create(function(env, session){

    var getUserlist = function(){

        if(!session.get('pageNum')){
            session.set('pageNum',1);
        }

        if(!session.get('pagesize')){
            session.set('pagesize',2);
        }

        var pageOptions = {
            pagesize : session.get('pagesize'), //每页显示的数目
            page : session.get('pageNum'), //当前页
            uniqueField : 'time' //排序的唯一字段
        };

        session.sduser = env.subscribeByPage('pub-sduser',pageOptions,function(sduserCollection,info){
            //manipulate synced collection and bind it to serveral view blocks.
            var page = info.page;

            session.bindByPage('sduserlist', {
                page: page,//返回的当前页数
                data: sduserCollection.find()
            });
        });
    }

    //获取数据库的大小
    var getModelCount = function(){
        env.subscribe('pub-modelCount', function(count){
            session.set('modelCount',count/session.get('pagesize'));

            console.log("modelCount1:"+session.get('modelCount'));
            session.bind('sduserlist', {
                count : count
            });
        });
    }

    //对于每一个loader，自动创建一个闭包。 监听其中session、collection的改变，作为reactive的source
    env.onload = function(){
        return [getUserlist,getModelCount];
    };

    env.onrender = function(doRender){
        doRender('display', ['rotate','left']);
    };

    env.onready = function(doc){
        session.event("sduserlist",function(){

            var event = "click";

            if(!!('ontouchstart' in window)){
                event = 'touchstart';
            }

            if(session.get('pageNum')==1 || session.get('pageNum')<session.get('modelCount')){
                document.getElementById('pre').disabled = true;
            }else{
                document.getElementById('pre').disabled = false;
            }

            console.log('test:'+session.get('pageNum')+'---'+session.get('modelCount'));

            if(session.get('pageNum')==session.get('modelCount') || session.get('pageNum')>session.get('modelCount')){

                console.log(session.get('pageNum')+'---'+session.get('modelCount'));

                document.getElementById('next').disabled = true;
            }else{
                document.getElementById('next').disabled = false;
            }

            //下一页
            document.getElementById('pre').addEventListener(event, function(){
                var pageNum = session.get('pageNum');
                pageNum--;

                session.set('pageNum',pageNum);
                session.commit();
            });

            //上一页
            document.getElementById('next').addEventListener(event, function(){
                var pageNum = session.get('pageNum');
                pageNum++;

                session.set('pageNum',pageNum);
                session.commit();
            });
        });

        //保存
        Library.touch.on('#sdsave', 'touchstart', function(){
            var name = document.getElementById('sdname').value;
            var age = document.getElementById('sdage').value;

            if(!name){
                name = "John";
            }

            if(!age){
                age="27";
            }
            session.sduser.add({"name":name,"age":age})
            session.sduser.save();
        });
    };
});
@@ -1236,163 +1236,10 @@
 '));
-%0A%0A            console.log(%22modelCount1:%22+session.get('modelCount'));%0A            session.bind('sduserlist', %7B%0A                count : count%0A            %7D);
+  
 %0A   
@@ -1574,33 +1574,32 @@
 st%22,function()%7B%0A
-%0A
             var 
@@ -1786,33 +1786,9 @@
 m')%3C
-session.get('modelCount')
+1
 )%7B%0A 
@@ -1953,98 +1953,8 @@
  %7D%0A%0A
-            console.log('test:'+session.get('pageNum')+'---'+session.get('modelCount'));%0A%0A
     
@@ -2072,95 +2072,8 @@
 ))%7B%0A
-%0A                console.log(session.get('pageNum')+'---'+session.get('modelCount'));%0A%0A
     
@@ -3245,11 +3245,12 @@
 %0A    %7D;%0A
-
 %7D);
+%0A

Update publishByPageController.js