加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

自己做的flex分页控件

发布时间:2020-12-15 04:33:49 所属栏目:百科 来源:网络整理
导读:?xml version="1.0" encoding="utf-8"? mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml " width="450" creationComplete="initPage()" mx:Script ![CDATA[ import com.adofits.framework.portal.base.communicate.MessageEvent; import mx.controls.Ale
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml " width="450" creationComplete="initPage()">
<mx:Script>
<![CDATA[
import com.adofits.framework.portal.base.communicate.MessageEvent;
import mx.controls.Alert;
public var totalPages:uint;
public var currentPage:uint;
public var pageRows:uint=10;
public var totalRows:uint;
public var pageStartRow:uint = 0;
public var pageEndRow:uint;
public var lastPageSize:uint;
public var step:uint;
public function initPage():void{
//totalPages = Math.ceil(totalRows / pageRows);
totalPages = totalRows % pageRows == 0 ?
totalRows / pageRows : totalRows / pageRows + 1;
lastPageSize=totalRows % pageRows;
preP.enabled = false;
firstP.enabled = false;
if(totalPages==0||totalPages == 1){
nextP.enabled = false;
lastP.enabled = false;
}
currentPage = 0;
pageStartRow = 0;
jilu_id.text="共"+String(totalRows)+"条记录";
page_id.text="共"+String(totalPages)+"页";
}
public function setButton():void{
if(currentPage==0){
firstP.enabled = false;
preP.enabled = false;
}
if(currentPage==totalPages-1){
lastP.enabled = false;
nextP.enabled = false;
}
if(currentPage<totalPages-1){
lastP.enabled = true;
nextP.enabled = true;
}
if(currentPage>0){
firstP.enabled = true;
preP.enabled = true;
}
pageNum.text = String(currentPage+1)+"/"+String(totalPages);
}
private function tofirst():void{
currentPage = 0;
pageStartRow = 0;
step=pageRows;
setButton();
dispatchEvent(new MessageEvent("pageRefreshed"));
}
private function toEnd():void{
currentPage = totalPages-1;
pageStartRow = currentPage*pageRows;
setButton();
dispatchEvent(new MessageEvent("pageRefreshed"));
}
private function next():void{
if(currentPage==totalPages-1){
Alert.show("当前已是最后一页!","提示");
return;
} else if(currentPage==totalPages-2){
step=lastPageSize;
} else{
step=pageRows;
}
currentPage++;
pageStartRow =currentPage*pageRows;
setButton();
this.dispatchEvent(new MessageEvent("pageRefreshed"));
}
private function pref():void{
if(currentPage==0){
Alert.show("当前已是第一页!","提示");
return;
}
step=pageRows;
currentPage--;
pageStartRow =currentPage*pageRows;
setButton();
this.dispatchEvent(new MessageEvent("pageRefreshed"));
}
private function findExacPage(thePage:uint):void{
if(currentPage==thePage){
return;
}
if(thePage<0||thePage>totalPages-1){
Alert.show("页面范围错误!","错误");
return;
}
if(thePage<=totalPages-2&&thePage>=0){
step= pageRows;
} else if(thePage==totalPages-1){
step=lastPageSize;
}
currentPage=thePage;
pageStartRow=currentPage*pageRows;
setButton();
this.dispatchEvent(new MessageEvent("pageRefreshed"));
}
]]>
</mx:Script>

<mx:Metadata>
[Event(name="pageRefreshed",type="com.adofits.framework.portal.base.communicate.MessageEvent")]
</mx:Metadata>
<mx:HBox width="100%" horizontalAlign="center" verticalAlign="middle">
<mx:Spacer />
<mx:HBox width="20%" horizontalAlign="left" verticalAlign="middle">
<mx:Label fontSize="11" text="转至" width="30%"/>
<mx:TextInput fontSize="11" id="gotoDestination" text="1" width="42"/>
<mx:Button fontSize="11" id="gotoExacPage" width="20%" click="findExacPage(uint(gotoDestination.text)-1)" styleName="MyButton" label="跳转"/>
</mx:HBox>
<mx:HBox width="40%" horizontalAlign="left" verticalAlign="middle">
<mx:Button id="firstP" fontSize="11" click="tofirst()" width="20%" label="|&lt;" styleName="MyButton"/>
<mx:Button id="preP" fontSize="11" click="pref()" width="20%" label="&lt;-" styleName="MyButton"/>
<mx:TextInput id="pageNum" fontSize="11" text="" width="58" editable="false"/>
<mx:Button id="nextP" fontSize="11" click="next()" width="20%" label="-&gt;" styleName="MyButton"/>
<mx:Button id="lastP" fontSize="11" click="toEnd()" width="20%" label="&gt;|" styleName="MyButton"/>
</mx:HBox>
<mx:HBox width="40%" horizontalAlign="left" verticalAlign="top">
<mx:Label fontSize="11" id="jilu_id" text="" width="30%"/>
<mx:Label fontSize="11" id="page_id" text="" width="30%"/>
</mx:HBox>
</mx:HBox>
</mx:VBox>

页面中调用的使用方法:
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml " width="100%" height="100%" xmlns:common="com.adofits.framework.portal.base.common.*" > <mx:Script> <![CDATA[ private function refreshed(e:com.adofits.framework.portal.base.communicate.MessageEvent):void{ var args:Array = new Array(pagechange.pageStartRow,pagechange.step,""); trace(args); opStatus.text = "正在载入..."; if(tabBarid.selectedIndex==0){ manager.invokeServiceWithToken("NoticeService","queryAllNotice",args,handleRefreshResult,handleRefreshFault); }else if(tabBarid.selectedIndex==1){ manager.invokeServiceWithToken("NoticeService","queryCollegeNotice",handleRefreshFault); } } private function handleRefreshResult(event:ResultEvent):void{ noticeInfoArray.removeAll(); perPageRows=pageRows.value; pagechange.setButton(); handleResult(event); } private function handleRefreshFault(event:FaultEvent):void{ handleFault(event); } private function refresh():void{ noticeInfoArray.removeAll(); perPageRows=pageRows.value; pagechange.initPage(); init(); } ]]> </mx:Script> <mx:HBox horizontalAlign="center" verticalAlign="middle" width="80%"> <common:PageChange id="pagechange" pageRefreshed="refreshed(event)" pageRows="{perPageRows}" totalRows="{rowCounts}" horizontalAlign="center" width="40%"/> </mx:HBox> 简化了页面的代码量,屡试不爽。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读