Flex与后台结合的分页
/*
* 与服务器后端结合数据分页...本站原创,抄袭注意完整
* Author:PHP技术博客,PHP博客 QQ:334192009
*/
public var pageI:int = 1//分配给click事件,初始页码量为1
public function page(action:String,pageI:int):void{
var pageSize:int = 1;//每页显示的记录数
//这里是总页数 根据这里的total.text数据总记录数(需要从服务器端获取) 取整
var maxRow:int = Math.ceil(int(total.text)/pageSize);
if(action == 'first'){
this.pageI = 1;
//调用服务器端得数据查询 参数如: LIMIT *,*
articles.getAllArticles((this.pageI - 1) * pageSize,pageSize);
}
if(action == 'previous'){
this.pageI = this.pageI - 1;
if(this.pageI < 1)
this.pageI = 1;
//调用服务器端得数据查询 参数如: LIMIT *,*
articles.getAllArticles((this.pageI - 1) * pageSize,pageSize);
}
if(action == 'next'){
this.pageI = this.pageI + 1;
if(this.pageI > maxRow)
this.pageI = maxRow;
//调用服务器端得数据查询 参数如: LIMIT *,*
articles.getAllArticles((this.pageI - 1) * pageSize,pageSize);
}
if(action == 'last'){
this.pageI = maxRow;
//调用服务器端得数据查询 参数如: LIMIT *,*
articles.getAllArticles((this.pageI - 1) * pageSize,pageSize);
}
}
]]>
</mx:Script>
<mx:Canvas width="100%" height="100%">
<mx:List width="100%" height="100%" dataProvider="{instance.articles}"
itemRenderer="views.listPage"
themeColor="#FCFCFC"/>
<mx:Text text="文章总数:" x="3" y="371" fontSize="12"/>
<mx:Label text="{instance.total}" id="total" y="371" x="57" fontSize="12"/>
<mx:Label id="first" text="首 页" fontSize="12" x="161" y="371" click="page('first',this.pageI)"
buttonMode="true" useHandCursor="true" mouseChildren="false" textDecoration="underline"/>
<mx:Label id="previous" text="上一页" fontSize="12" x="192" y="371" click="page('previous',this.pageI)"
buttonMode="true" useHandCursor="true" mouseChildren="false" textDecoration="underline"/>
<mx:Label id="next" text="下一页" fontSize="12" x="231" y="371" click="page('next',this.pageI)"
buttonMode="true" useHandCursor="true" mouseChildren="false" textDecoration="underline"/>
<mx:Label id="last" text="未 页" fontSize="12" x="271" y="371" click="page('last',this.pageI)"
buttonMode="true" useHandCursor="true" mouseChildren="false" textDecoration="underline"/>
</mx:Canvas>
</mx:VBox>