flex分页控件
小程序实现分页效果

/** * 生命周期函数--监听页面卸载 */ onUnload: function () {
},
/** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () {
},
/** * 页面上拉触底事件的处理函数 */ onReachBottom: function () {
这篇文章主要介绍了微信小程序后端开发流程的详细步骤文中通过示例代码介绍的非常详细对大家的学习或者工作具有一定的参考学习价值需要的朋友们下面随着小编来一起学习学习吧
小程序实现分页效果
本文实例为大家分享了小程序实现分页效果展示的具体代码,供大家参考,具体内容如下
<view class="pages_box"> <view bindtap="pagesFn" class="{{pagesNum==0?'active':''}}" data-type="0">上一页</view> <block wx:for="shujuDataArr11111" wx:key="index" wx:if="{{index+1<4}}"> <view wx:if="{{tyindex+index <=maxPages}}" bindtap="pagesFn" class="{{pagesNum==tyindex+index?'active':''}}" data-type="{{tyindex+index}}">{{tyindex+index}}</view> </block> <view bindtap="pagesFn" class="{{pagesNum==-1?'active':''}}" data-type="-1">下一页</view>
flex 的用法

flex 的用法“flex”的用法“flex”是一种用于实现响应式布局的CSS工具。
它是“Flexible Box Layout”的缩写,也称为flexbox。
flexbox提供了一种灵活的方式来布置、对齐和分布元素,以适应不同的屏幕尺寸和设备类型。
在本文中,我们将一步一步回答以下关于“flex”的用法的问题:1. 什么是“flex”?2. 如何使用"flex"创建一个简单的布局?3. 如何在flex容器和flex项目中设置属性?4. 如何进行flex项目的对齐和分布?5. 如何在媒体查询中使用“flex”?6. 一些常见的“flex”应用示例。
7. “flex”的浏览器兼容性。
1. 什么是“flex”?“flex”是一种CSS布局技术,用于创建响应式布局。
它基于flexbox模型,其中包含一个flex容器和flex项目。
flex容器是一个包含flex项目的容器,而flex项目则是flex容器中的子元素。
2. 如何使用"flex"创建一个简单的布局?要创建一个简单的flex布局,首先需要创建一个flex容器。
我们使用`display: flex;`来将一个元素设置为flex容器。
接下来,我们可以使用其他属性来设置容器的方向、换行、对齐等属性。
css.container {display: flex;flex-direction: row;justify-content: space-between;align-items: center;}在上面的示例中,我们将一个元素的类名设置为“container”,然后使用`display: flex;`将其设置为flex容器。
接下来,我们使用`flex-direction: row;`设置容器内项目的排列方向为水平方向,使用`justify-content: space-between;`设置项目之间的间距,使用`align-items: center;`设置项目在容器中的垂直方向上的对齐方式。
【UNI-APP】分页请求数据列表

【UNI-APP】分页请求数据列表// ⾸先在对应的pages.json⽂件中,配置刷新效果{"path" : "pages/list/list","style" :{"navigationBarTitleText": "房源列表","enablePullDownRefresh": true}}// 在methods⾥⾯定义请求数据接⼝// 请求第1页的数据getList() {this.listData = []uni.request({url: 'http://localhost:8000/api/house/list?page=1&size=7',method: "POST",header: {'content-type': 'application/x-www-form-urlencoded'},data: {style: 1,},success: (ret) => {uni.stopPullDownRefresh(); // 停⽌当前页⾯刷新if (ret.data.code == 200) {ret.data.data.some((item, i) => {this.listData.unshift({title: item.title,price: item.price,id: item.id,image: "http://localhost:8000" + item.image,time: item.time,})})// this.banner = data.data;}},fail: (data, code) => {console.log('fail' + JSON.stringify(data));}})},// 请求第N页的数据/* 分页请求 */getPageList() {uni.request({url: 'http://localhost:8000/api/house/list?page=' + this.page + '&size=7',method: "POST",header: {'content-type': 'application/x-www-form-urlencoded'},data: {style: 1,},success: (ret) => {console.log(ret)uni.stopPullDownRefresh(); // 停⽌当前页⾯刷新if (ret.data.code == 200) {this.page = this.page + 1 // 页⾯+1ret.data.data.some((item, i) => {this.listData.push({title: item.title,price: item.price,id: item.id,image: "http://localhost:8000" + item.image,time: item.time,})})} else {/* 如果接⼝报错就是没数据加载消失 */ // <!-- 下拉加载 --> 加载HTML // <view style="text-align: center;width: 100%;"> // <u-loading mode="circle" :show="show" size="36">加载中...</u-loading> // </view>this.show = false}},fail: (data, code) => {}})},// 下⾯是下拉上啦的配置函数onLoad() {/* 列表 */this.getList();},onPullDownRefresh() {/* 下拉的时候更新 */this.getList();},onReachBottom() {// console.log("向下拉")//此处使⽤定时器可查看出下拉刷新效果setTimeout(() => {this.getPageList(() => {uni.stopPullDownRefresh()})}, 1000)},// 完整代码<template><view><!-- 输⼊框搜索 --><view><topSearch></topSearch></view><!-- 下拉菜单 --><u-dropdown><u-dropdown-item v-model="housePrice" title="价格⾼低" :options="optionsPrice" @change="changePrice"></u-dropdown-item><u-dropdown-item v-model="houseTime" title="发布时间" :options="optionsTime" @change="changeTime"></u-dropdown-item></u-dropdown><!-- 商品列表 --><view class="uni-list"><view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(value,key) in listData" :key="key" @click="detail(value.id)":pk="value.id"><view class="uni-media-list"><image class="uni-media-list-logo" :src="value.image"></image><view class="uni-media-list-body"><view class="uni-media-list-text-top">{{value.title}}</view><text>123</text><view class="uni-media-list-text-bottom"><text>{{value.price}}</text><text>{{value.time}}</text></view></view></view></view></view><!-- 下拉加载 --><view style="text-align: center;width: 100%;"><u-loading mode="circle" :show="show" size="36"></u-loading></view></template><script>import topSearch from "@/components/topSearch/topSearch.vue" var dateUtils = require('../../utils/util.js').dateUtils;export default {components: {topSearch},data() {return {/* 商品列表 */listData: [],last_id: "",reload: false,page: 1,show: true,/* 下拉菜单 */sort:1,houseprice: 1,houseTime: null,optionsPrice: [{label: '默认排序',value: 1,},{label: '从低到⾼',value: 2,},{label: '从⾼到低',value: 3,}],optionsTime: [{label: '最近发布',value: 4,},{label: '最早发布',value: 5,},],}},methods: {/* 跳转详情 */detail(goods_id) {/* 记录商品主键 */// uni.setStorageSync('goods_id',)console.log(goods_id)// uni.navigateTo({// url: '/pages/detail/detail'// })},/* 下拉菜单 */changePrice() {this.sort = this.housePricethis.getList()},changeTime() {this.sort = this.houseTimethis.getList()},/* 刚进⼊请求接⼝ */getList() {/* 初始化参数 */this.page = 1this.listData = []uni.request({url: 'http://localhost:8000/api/house/list?page=1&size=7',method: "POST",header: {'content-type': 'application/x-www-form-urlencoded'},data: {style: uni.getStorageSync('style'),sort:this.sort},success: (ret) => {uni.stopPullDownRefresh(); // 停⽌当前页⾯刷新if (ret.data.code == 200) {this.page = this.page + 1ret.data.data.some((item, i) => {this.listData.unshift({title: item.title,price: item.price,id: item.id,image: "http://localhost:8000" + item.image,time: item.time,})})this.show = false}},fail: (data, code) => {console.log('fail' + JSON.stringify(data));}})},/* 分页请求 */getPageList() {this.show = trueuni.request({url: 'http://localhost:8000/api/house/list?page=' + this.page + '&size=7', method: "POST",header: {'content-type': 'application/x-www-form-urlencoded'},data: {style: uni.getStorageSync('style'),sort:this.sort},success: (ret) => {// console.log(ret)uni.stopPullDownRefresh(); // 停⽌当前页⾯刷新if (ret.data.code == 200) {this.page = this.page + 1ret.data.data.some((item, i) => {this.listData.push({title: item.title,price: item.price,id: item.id,image: "http://localhost:8000" + item.image,time: item.time,})})} else {/* 如果接⼝报错就是没数据加载消失 */this.show = false}},fail: (data, code) => {this.show = false}})},},/* 列表 */this.getList();},onPullDownRefresh() {/* 下拉的时候更新 */this.getList();},onReachBottom() {console.log("向下拉")//此处使⽤定时器可查看出下拉刷新效果 setTimeout(() => {this.getPageList(() => {uni.stopPullDownRefresh()})}, 1000)},}</script><style>/* 列表 */.banner {height: 360upx;overflow: hidden;position: relative;background-color: #ccc;}.banner-img {width: 100%;}.banner-title {max-height: 84upx;overflow: hidden;position: absolute;left: 30upx;bottom: 30upx;width: 90%;font-size: 32upx;font-weight: 400;line-height: 42upx;color: white;z-index: 11;}.uni-list {background-color: #FFFFFF;position: relative;width: 100%;display: flex;flex-direction: column;}.uni-list:after {position: absolute;z-index: 10;right: 0;bottom: 0;left: 0;height: 1px;content: '';-webkit-transform: scaleY(.5);transform: scaleY(.5);background-color: #c8c7cc;}.uni-list::before {position: absolute;z-index: 10;right: 0;top: 0;left: 0;height: 1px;content: '';-webkit-transform: scaleY(.5);transform: scaleY(.5);background-color: #c8c7cc;}.uni-list-cell {position: relative;display: flex;flex-direction: row;justify-content: space-between; align-items: center;}.uni-list-cell-hover {background-color: #eee;}.uni-list-cell::after {position: absolute;z-index: 3;right: 0;bottom: 0;left: 30upx;height: 1px;content: '';-webkit-transform: scaleY(.5);transform: scaleY(.5);background-color: #c8c7cc;}.uni-list .uni-list-cell:last-child::after { height: 0upx;}/* 图⽂列表 */.uni-media-list {padding: 22upx 30upx;box-sizing: border-box;display: flex;width: 100%;flex-direction: row;}.uni-navigate-right.uni-media-list { padding-right: 74upx;}.uni-pull-right {flex-direction: row-reverse;}.uni-pull-right>.uni-media-list-logo { margin-right: 0upx;margin-left: 20upx;}.uni-media-list-logo image {height: 100%;width: 100%;}.uni-media-list-text-bottom {width: 100%;line-height: 30upx;font-size: 26upx;color: #8f8f94;}.uni-media-list-logo {width: 180upx;height: 140upx;margin-right: 20upx;}.uni-media-list-body {display: flex;flex: 1;flex-direction: column;justify-content: space-between; align-items: flex-start;overflow: hidden;height: auto;}.uni-media-list-text-top {width: 100%;line-height: 36upx;font-size: 30upx;height: 74upx;font-size: 28upx;overflow: hidden;}.uni-media-list-text-bottom {display: flex;flex-direction: row;justify-content: space-between; }/* 列表 */</style>。
flex——弹性布局的属性及使用

1.父元素id为flex,子元素class为items#flex {width: 100%;height: 100%;display: flex;padding:15px;padding-top: 200px;border: 1px solid red;box-sizing: border-box;}#flex .items {width: 18%;border: 1px solid blue;height: 200px;}效果如下图2.flex-direction 在flex容器里的所有的block元素的流动方向row 默认,从左到右column 从上到下row-reverse 从右到左column-reverse 从上到下父元素添加flex-direction: row;父元素添加flex-direction:row-reverse父元素添加flex-direction:column父元素添加flex-direction:column-reverse3.flex-wrap 控制如果当前行的位置不足时,是否换行,默认是不换行,会一直在一行中挤压,会改变在该行元素的宽度,将其排在一行之中nowrap 不换行wrap 换行,空间不足,就向下另起一行。
wrap-reverse 换行,与wrap不同的是,这个是向当前行的上面另起一行。
注意:flex-direction和flex-wrap经常一起使用所有有个缩写属性flex-flow:flex-direction flex-wrap。
父元素添加flex-flow:row nowrap;父元素添加flex-flow:row wrap;父元素添加flex-flow:row wrap-reverse;4.justify-content主轴的对齐方式,元素在容器中的对齐方式,与左对齐,右对齐,居中对齐类似取值:flex-start 靠近主轴的开始方向,如果从左到右就靠左,相反就靠右。
Flexbox布局指南用CSS轻松实现灵活的网页布局

Flexbox布局指南用CSS轻松实现灵活的网页布局Flexbox布局指南:用CSS轻松实现灵活的网页布局CSS的Flexbox布局(弹性盒子布局)是一种能够快速实现灵活网页布局的强大工具。
它提供了一种直观且易于使用的方式来构建响应式布局,适用于各种屏幕尺寸和设备。
本文将为您介绍Flexbox布局的基本概念、核心属性和常见用法,帮助您快速上手使用Flexbox布局。
1. Flexbox布局基础Flexbox布局主要由容器(Container)和项目(Item)两个基本概念组成。
容器是一种包含了需要布局的项目的父元素,而项目则是容器中被布局的子元素。
通过对容器应用Flexbox布局属性,我们可以轻松地控制项目的排列方式、对齐方式和尺寸分配。
2. 容器属性2.1 display在使用Flexbox布局时,我们需要将容器的display属性设置为flex 或inline-flex,以使其成为一个Flex容器。
flex将使容器使用块级元素的布局方式,而inline-flex则使用行级元素的布局方式。
2.2 flex-directionflex-direction属性用于确定项目的排列方向。
它有四个可能的值:row、row-reverse、column和column-reverse。
设置为row时,项目水平排列;设置为column时,项目垂直排列;而设置为row-reverse和column-reverse则分别将项目在水平和垂直方向上进行反向排列。
2.3 flex-wrapflex-wrap属性决定了项目的换行方式。
它有三个可能的值:nowrap (默认值,不换行)、wrap(换行)和wrap-reverse(反向换行)。
通过设置wrap属性,我们可以使项目自动换行,以适应容器的尺寸变化。
2.4 justify-contentjustify-content属性用于确定项目在主轴上的对齐方式。
主轴是由flex-direction属性决定的。
thinkphp5.1+layui应用分页

thinkphp5.1+layui应⽤分页以往⽤原⽣时,若要在项⽬上使⽤分页,后端代码经常要⼀整页,现在使⽤thinkphp之后才发现曾经复杂的后端代码简单到了极致,直接⽤官⽅提供的paginate() ⽅法就可以很简单的实现了,废话少说,接下来⽤代码实现⼀个完整的电脑端分页功能。
⾸先,引⼊layui⽂件(我这⾥是放在public⾥⾯的web_static⽂件夹下,并全局使⽤,建议新⼿也全局使⽤,不然可能要写很多兼容样式,之前写⼀个站的兼容的时候真的太痛苦了)<link rel="stylesheet" href="/web_static/layui/css/layui.css"/>接下来是html页⾯<div style="width: 1200px;margin: 0 auto;"><div><div id="allGuests" style="display: flex;flex-direction: row;flex-wrap: wrap">{foreach $list['data'] as $key => $vo }<div style="width: 30%;margin: 20px;box-sizing: border-box;border: 1px solid #e2e2e2;border-radius: 10px;overflow: hidden;"><a href="{:url('/web/demo_content','detail='.$vo['id'])}"><img style="width: 100%;height: 300px;object-fit: cover;" src="https:///{$vo.img}"><div style="text-align: center;font-size: 18px;line-height: 50px;">{$}</div></a></div>{/foreach}</div><!--分页--><div style="width:1200px;text-align:center;margin: 0 auto;"><div id="paging" class="paging" style="background-color: transparent;"></div></div></div></div>上⾯foreach内的内容是要循环的数据,因为下⾯会⽤到,所以先说明。
Flex布局做出自适应页面(语法和案例)
Flex布局做出⾃适应页⾯(语法和案例)Flex布局简介Flex英⽂为flexiable box,翻译为弹性盒⼦,Flex布局即弹性布局。
Flex布局为盒⼦模型提供了很⼤的灵活性,任何⼀个容器都可以指定为Flex布局,设置⽅法为:.box{display: flex;}⾏内元素使⽤Flex布局.box{display: inline-flex;}在webkit内核的浏览器上必须加上webkit前缀.box{display: flex;display: -webkit-flex;}注意:使⽤Flex布局之后,⾥⾯的float、clear、vertical-align属性将失效。
Flex布局中的基本概念采⽤ Flex 布局的元素,称为 Flex 容器(flex container),简称"容器"。
它的所有⼦元素⾃动成为容器成员,称为 Flex 项⽬(flex item),简称"项⽬"。
容器默认存在两根轴:⽔平的主轴(main axis)和垂直的侧轴(cross axis)。
主轴的开始位置(与边框的交叉点)叫做main start,结束位置叫做main end;侧轴的开始位置叫做cross start,结束位置叫做cross end。
项⽬默认沿主轴排列。
单个项⽬占据的主轴空间叫做main size,占据的侧轴空间叫做cross size。
容器的属性1、flex-driection2、flex-wrap3、flex-flow4、justify-content5、align-items6、align-content1、flex-driection设置项⽬的排列⽅向,默认为rowflex-driection: row | row-reverse | column | column-reverse当设置为flex-driection: row,效果:当设置为flex-driection: row-reverse,效果:当设置为flex-driection: column,效果:当设置为flex-driection: column-reverse,效果:如下代码直接复制保存为html⽂件即可以查看效果:<style type="text/css">.box{display: flex;display: -webkit-flex;/*⽔平⽅向,左端对齐*/flex-direction: row;/*⽔平⽅向,右端对齐*//*flex-direction: row-reverse;*//*垂直⽅向,顶部对齐*//*flex-direction: column;*//*垂直⽅向,底部对齐*//*flex-direction: column-reverse;*/background: #999;width: 100%;}.box span{margin: 10px 10px;padding: 10px;background: #ff0;width: 50px;}</style><div class="box"><span>你好1</span><span>你好2</span><span>你好3</span><span>你好4</span></div>2、flex-wrap设置项⽬是否在⼀条线上,默认为nowrapflex-wrap: wrap | nowrap | wrap-reverse当设置为flex-wrap: wrap,效果:当设置为flex-wrap: nowrap,效果(不换⾏,默认会缩放):当设置为flex-wrap: wrap-reverse,效果(第⼀⾏在下⽅):如下代码直接复制保存为html⽂件即可以查看效果:<style type="text/css">.box{display: flex;display: -webkit-flex;/*换⾏*//*flex-wrap: wrap;*//*不换⾏,默认*//*flex-wrap: nowrap;*//*换⾏,第⼀⾏在下⽅*//*flex-wrap: wrap-reverse;*/background: #999;width: 100%;}.box span{margin: 10px 10px;padding: 10px;background: #ff0;width: 50px;}</style><div class="box"><span>你好1</span><span>你好2</span><span>你好3</span><span>你好4</span><span>你好5</span><span>你好6</span><span>你好7</span></div>3、flex-flow属性是flex-direction属性和flex-wrap属性的简写形式,默认值为row nowrap4、justify-content属性定义项⽬在主轴上的对齐⽅式,默认值为flex-startjustify-content: flex-start | flex-end | center | space-between | space-around当设置为justify-content: flex-start,效果:当设置为justify-content: flex-end,效果:当设置为justify-content: center,效果:当设置为justify-content: space-between,效果:当设置为justify-content: space-around,效果:如下代码直接复制保存为html⽂件即可以查看效果:<style type="text/css">.box{display: flex;display: -webkit-flex;/*默认,项⽬左对齐*/justify-content: flex-start;/*项⽬右对齐*//*justify-content: flex-end;*//*项⽬居中对齐*//*justify-content: center;*//*项⽬两端对齐*//*justify-content: space-between;*//*每个项⽬两侧的间隔相等*//*justify-content: space-around;*/background: #999;width: 100%;}.box span{margin: 10px 10px;padding: 10px;background: #ff0;width: 50px;}</style><div class="box"><span>你好1</span><span>你好2</span><span>你好3</span><span>你好4</span><span>你好5</span><span>你好6</span><span>你好7</span></div>5、align-items属性定义项⽬在纵轴上的对齐⽅式,默认值为stretch,适⽤于项⽬在纵轴上⾼度不⼀样的情况,为了更好的看到效果,我为项⽬添加了⼀些样式align-items: flex-start | flex-end | center | baseline | stretch当设置为align-items: flex-start,效果:当设置为align-items: flex-end,效果:当设置为align-items: center,效果:当设置为align-items: baseline,效果:当设置为align-items: stretch,效果:如下代码直接复制保存为html⽂件即可以查看效果:<style type="text/css">.box{display: flex;display: -webkit-flex;/*纵轴的顶部对齐*//*align-items: flex-start;*//*纵轴的底部对齐*//*align-items: flex-end;*//*纵轴的中点对齐*//*align-items: center;*//*项⽬的第⼀⾏⽂字的基线对齐*//*align-items: baseline;*//*默认对齐⽅式,如果项⽬未设置⾼度或设为auto,将占满整个容器的⾼度*/align-items: stretch;background: #999;width: 100%;}.box span{margin: 10px 10px;padding: 10px;background: #ff0;width: 50px;}.box span:nth-of-type(2n){height: 80px;padding-top: 20px;}</style><div class="box"><span>你好1</span><span>你好2</span><span>你好3</span><span>你好4</span><span>你好5</span><span>你好6</span><span>你好7</span></div>6、align-content属性定义了多根轴线的对齐⽅式。
msflexgrid控件用法
msflexgrid控件用法MSFlexGrid控件是Visual Basic 6.0提供的一种非常有用的表格控件,可以在窗体中创建可编辑的网格。
它允许用户浏览和编辑多行和多列的数据,还可以对数据进行排序、过滤和格式化。
在本文中,我将详细介绍MSFlexGrid控件的用法,包括创建、显示和操作表格数据。
一、创建和显示MSFlexGrid控件在使用MSFlexGrid控件之前,首先需要在窗体中添加一个FlexGrid控件。
在VB6的工具箱中,可以找到FlexGrid控件并将其拖放到窗体上。
在窗体上添加FlexGrid控件后,可以通过设置控件的属性来进行进一步的配置和定制。
1. 设置列数和行数在使用MSFlexGrid控件之前,首先需要设置表格的列数和行数。
可以通过设置Col属性和Row属性来实现。
例如,设置表格的列数为5,行数为10的代码示例如下:MSFlexGrid1.Cols = 5MSFlexGrid1.Rows = 102. 设置表格显示样式可以通过设置控件的属性来设置表格的样式,例如,可以设置表格的边框颜色、背景颜色和字体。
以下是一些常用的属性设置示例:MSFlexGrid1.BorderStyle = flexBorderStyleFixedSingle ' 设置边框样式为单线条MSFlexGrid1.BackColor = vbWhite ' 设置背景颜色为白色MSFlexGrid1.ForeColor = vbBlack ' 设置前景颜色为黑色MSFlexGrid1.FontSize = 12 ' 设置字体大小为12号3. 添加数据到表格可以通过设置控件的TextMatrix属性来添加数据到表格中。
TextMatrix属性是一个二维数组,可以通过指定行和列的索引来设置相关的数据。
例如,将数据“Apple”添加到(1,1)位置的代码示例如下:MSFlexGrid1.TextMatrix(1, 1) = "Apple"二、操作MSFlexGrid控件中的数据在将数据添加到表格之后,可以对表格中的数据进行许多操作,例如,读取单元格数据、排序和过滤数据等。
Flex4自定义分页组件
Flex4自定义分页组件最近因为项目需求,需要写个分页组件,我这人比较懒一般写出来之后就记下来供以后粘贴复制了哈哈,希望大家学习的时候不要这样搞啊下面贴出代码PagingBar.mxml[html]<?xml version="1.0" encoding="utf-8"?><mx:HBox xmlns:fx=":///mxml/2009"xmlns:s="library:///flex/spark"xmlns:mx="library:///flex/mx" ><fx:Script><![CDATA[import mx.collections.ArrayCollection;import mx.events.ItemClickEvent;import flash.events.KeyboardEvent;import mx.controls.DataGrid;import mx.validators.NumberValidator;import mx.rpc.events.ResultEvent;import mx.rpc.events.FaultEvent;import mx.controls.Alert;[Bindable][Embed(source='com/iman/sps/sheet/image/first.jpg')]public var firstIcon:Class;public var firstPage:uint;[Bindable][Embed(source='com/iman/sps/sheet/image/pre.jpg')]public var preIcon:Class;public var prePage:uint;[Bindable][Embed(source='com/iman/sps/sheet/image/next.jpg')]public var nextIcon:Class;public var nextPage:uint;[Bindable][Embed(source='com/iman/sps/sheet/image/last.jpg')]public var lastIcon:Class;public var lastPage:uint;[Bindable]public var pageSize:int=15;//单页行数[Bindable]public var totalPage:int=1;//总页数[Bindable]public var currentPage:int=1;//当前页[Bindable]public var totalClum:int=0;//总记录数//分页函数public var localFunction:Function=null;//重新为当前页的变量赋值public function loadData(pageNum:int):void{this.pageSize = setPageSize.selectedItem.data as Number;this.totalPage =Math.ceil(this.totalClum/this.pageSize);if(pageNum>0 && pageNum<=this.totalPage){this.currentPage=pageNum;if(this.localFunction!=null){localFunction(pageNum);}else{Alert.show("请设置回调方法!");}}}//重新设置每页显示记录数public function changePagesize():void{//当前页首条记录的序号var currentPageRows:int=((this.currentPage-1)*this.pageSize);//Alert.show(String(currentPageRows));//重新设置以后,单页显示记录数this.pageSize = setPageSize.selectedItem.data as Number;//重新设置以后,总页数this.totalPage =Math.ceil(this.totalClum/this.pageSize);//重新调整当前页码//Alert.show(String(newPageNum));if(this.localFunction!=null){localFunction(this.currentPage);}else{Alert.show("请设置回调方法!");}}]]></fx:Script><mx:Text id="temp" text="" visible="false" includeInLayout="false"/><mx:HBoxverticalGap="0"horizontalGap="0"horizontalAlign="center"verticalAlign="middle"><mx:Text text="{' 共'+(totalClum)+'条记录'}" fontSize="12"/><mx:Label text="每页显示:"/><mx:ComboBox id="setPageSize" width="52" height="16" change="changePagesize()"><mx:dataProvider><fx:Array><fx:Object label="15" data="15" /><fx:Object label="20" data="20" /><fx:Object label="30" data="30" /><fx:Object label="40" data="40" /><fx:Object label="50" data="50" /><fx:Object label="60" data="60" /><fx:Object label="70" data="70" /><fx:Object label="80" data="80" /></fx:Array></mx:dataProvider></mx:ComboBox><mx:Label text="条"/><mx:Button id="firstNavBtn" icon="{firstIcon}" width="10" height="10" click="loadData(1)" enabled="{lbtnPrevious.enabled}"/><mx:LinkButton id="lbtnFirst" label="首页" click="loadData(1)" enabled="{lbtnPrevious.enabled}" fontSize="12"/><mx:Button id="preNavBtn" icon="{preIcon}" width="7" height="10" click="loadData(currentPage-1)" enabled="{currentPage!=1?true:false}"/><mx:LinkButton id="lbtnPrevious" label="上一页" click="loadData(currentPage-1)" enabled="{currentPage!=1?true:false}" fontSize="12"/><mx:Text text="{'【 '+(Math.ceil(this.totalClum/this.pageSize)>0?(currentPage):1)+'/'+(Math.ceil(this.totalClum/this.pageSize)>0?Math.ceil(this.totalClum/this.pageSize):1)+'页】 '}" fontSize="12"/><mx:Button id="nextNavBtn" icon="{nextIcon}" width="7" height="10" click="loadData(currentPage+1)" enabled="{Math.ceil(this.totalClum/this.pageS ize)>(currentPage)?true:false}"/><mx:LinkButton id="lbtnNext" label="下一页" click="loadData(currentPage+1)" enabled="{Math.ceil(this.totalClum/this.pageSize)>(currentPage)?true:false}" fontSize="12"/><mx:Button id="lastNavBtn" icon="{lastIcon}" width="10" height="10" click="loadData(Math.ceil(this.totalClum/this.pageSize))" enabled="{lbtnNext.en abled}"/><mx:LinkButton id="lbtnLast" label="尾页" click="loadData(Math.ceil(this.totalClum/this.pageSize))" enabled="{lbtnNext.enabled}" fontSize="12"/><mx:Label text="跳转到"/><mx:NumericStepper id="nsPageNum" width="50" height="22" stepSize="1" minimum="1" maximum="{Math.ceil(this.totalClum/this.pageSize)}" enab led="{lbtnJump.enabled}" cornerRadius="0" fontSize="12"/><mx:Label text="页"/><mx:LinkButton id="lbtnJump" label="GO" click="loadData(nsPageNum.value)" enabled="{Math.ceil(this.totalClum/this.pageSize)>1?true:false}" fontS ize="12"/></mx:HBox></mx:HBox>在其他组件中引用其中common 是我自定义的标签里面引入了这个分页组件的所在位置例如:xmlns:common="mon.*"[html]<common:PagingBar width="100%" height="5%" id="pageBar"></common:PagingBar>写完之后说说怎么用。
第5章_Flex组件简介
Flex组件简介目录Flex Flex组件概述组件概述1控件的基本使用方法2工具提示3基于菜单的控件45基于容器的布局规则Flex Flex容器组件容器组件容器组件,,导航控件67Form Form表单使用表单使用Flex Flex内建了很多内建了很多内建了很多UI UI UI控件控件控件,,组件这个概念在大多数语言中也被称为控件大多数语言中也被称为控件。
Flex Flex控件基本分为三种类型控件基本分为三种类型控件基本分为三种类型::Flex 控件概述基于文本框的空件基于按钮的控件基于列表的控件控件功能描述Alert弹出一个警告框弹出一个警告框,,该控件必须使用代码触发该控件必须使用代码触发,,所以在组件视图中没有改组件的图标Button显示一个按钮显示一个按钮,,按钮上可以包含标签文件或者图标按钮上可以包含标签文件或者图标,,或者二者同时包含ComboBox显示一个组合框DateGrid显示一个表格格式的列表可用控件DateField显示一个文本框显示一个文本框,,右边带有日历图标右边带有日历图标,,单击图标可以选择日期Image可以动态加载一个可以动态加载一个GIF GIF GIF、、JPEG JPEG、、PNG PNG、、SVG SVG、、SWF SWF格式的文件格式的文件Label显示一个标签List显示为一个可滚动的单选或者多选列表框Text显示一个多行的文本框显示一个多行的文本框,,文本框中的内容不可编辑TextArea显示一个多行的文本框显示一个多行的文本框,,文本框中的内容可编辑TextInput显示一个单行文本框显示一个单行文本框,,文本框中的内容可编辑Tree 以树状形势显示一系列节点数据控件功能描述CheckBox显示一个复选框ColorPicker显示包含一个或多个样本的列表显示包含一个或多个样本的列表,,用户可以从中选择颜色DateChooser显示一个允许用户选择日期的日历FormItemLabelFormItem容器使用该对象显示标签可用控件FormItem 容器使用该对象显示标签HorizontalList水平显示一系列项目HRule HRule、、VRule显示一个水平分割线或者是垂直分割线HScrollBar HScrollBar、、VScrollBar显示一个水平滚动条或者是垂直滚动条HSlider HSlider、、VSlider 显示一个水平刻度尺或者是垂直刻度尺LinBar将多个超链接显示为一行将多个超链接显示为一行,,超链接具有相同的呈现LinkButton 显示为一个超链接控件功能描述RadioButton 显示为一个单选按钮RadioButtonGroup 显示为一个单选按钮组TabBar形成一个水平选项卡TileList显示一个可以水平、可用控件显示一个可以水平、水平排列条目的列表ToolTip显示一个工具提示框VideoDisplay显示流媒体数据ButtonBar将多个按钮显示为一行将多个按钮显示为一行,,按钮具有相同的呈现Menu显示一个菜单显示一个菜单,,必须使用代码创建MenuBar 显示一个水平菜单栏控件功能描述RichTextEditor 显示一个富文本编辑器AdvancedDataGrid 增强的增强的DataGrid DataGrid DataGrid控件控件NumbericStepper 显示一个进步组合框显示一个进步组合框,,有两个按钮和一个文本框组成联机分析处理DataGrid 可用控件OLAPDataGrid联机分析处理DataGrid DataGrid控件控件控件,,是增强的是增强的DataGrid DataGrid DataGrid控控件PopUpButton显示一个按钮显示一个按钮,,但是单击可以弹出一个类表PopUpMenuButton 显示为一个按钮显示为一个按钮,,但是单击可以弹出一个菜单ProgressBar显示一个过程条显示一个过程条,,用于呈现加载内容的进度Spacer该控件用来辅助布局SWFLoader 显示一个显示一个SWF SWF SWF文件或者文件或者文件或者JPEG JPEG JPEG文件的内容文件的内容控件的使用方法一些控件是可以在一些控件是可以在MXML MXML MXML标签直接呈现标签直接呈现标签直接呈现,,另外一些则是在另外一些则是在ActionScript ActionScript ActionScript中使用中使用中使用,,例如例如::Alert Alert控件控件控件。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
设计思想是参考中的 ASPNETPager分页控件的思想。
参数:
属性:
RecordCount 总记录条数
PageSize 每页大小
PageCount 总页数
PageIndex 当前页码
StartIndex 开始记录数,用于分页查询
事件:
pageChanged 分页触发时的事件
需要自己写两个查询方法
1.GetRecordCount返回总条数
2.GetDataByPage(StartIndex,PageSize) 从开始记录取PageSize条记录,就可以完成分页功能(具体使用方法可以参考ASPNET Pager控件)
源码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="/2006/mxml" layout="absolute"
width="678"
initialize="init();"
height="20">
<mx:Metadata>
[Event(name="pageChanged",type="mx.rpc.events.ResultEvent")]
</mx:Metadata>
<mx:Script>
<![CDATA[
import mx.controls.LinkButton;
import mx.events.ItemClickEvent;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
public var PageCount:int=0;
public var RecordCount:int=0;
public var PageSize:int=10;
public var PageIndex:int=0;
public var StartIndex:int=0;
private function init():void{
lb.dataProvider= [{label:"|<",text:"首页"},{label:"<<",text:"上一页"},{label:">>",text:"下一页"},{label:">|",text:"末页"}];
}
public function setRecordCount(count:int):void{
this.RecordCount=count;
if(count%PageSize==0)
PageCount=count/PageSize;
else
PageCount=count/PageSize+1;
pg(PageIndex);
refUI();
}
public function refUI():void{
info.text="共"+RecordCount+"条记录每页"+PageSize+"条共"+PageCount+"页第
"+(PageIndex+1)+"页";
(lb.getChildAt(0) as LinkButton).enabled=(lb.getChildAt(1) as LinkButton).enabled=PageIndex>0;
(lb.getChildAt(2) as LinkButton).enabled=(lb.getChildAt(3) as LinkButton).enabled=PageIndex<PageCount-1;
}
private function click(e:ItemClickEvent):void{
var n:int= e.index;
var index:int=PageIndex;
switch(n){
case 0:
index=0;
break;
case 1:
index--;
break;
case 2:
index++;
break;
default:
index=PageCount-1;
break;
}
pg(index);
}
private function pg(index:int):void{
if(index<0) index=0;
if(index>PageCount-1) index=PageCount-1;
PageIndex=index;
StartIndex=PageIndex*PageSize;
var ev:ResultEvent=new ResultEvent("pageChanged",false,true,PageIndex);
dispatchEvent(ev);
setTimeout(refUI,200);
}
private function gopg():void{
var n:int=new Number(txtpg.text);
n--;
pg(n);
}
]]>
</mx:Script>
<mx:Box width="100%" direction="horizontal" paddingTop="2">
<mx:Label y="1" id="info" text="共100条记录每页20条共90页第1页" height="18"/> <mx:LinkBar id="lb" labelField="label" toolTipField="text" separatorWidth="0" fontSize="8" paddingLeft="0" paddingRight="0" itemClick="click(event)">
</mx:LinkBar>
<mx:TextInput height="16" y="2" width="30" id="txtpg" paddingBottom="0" paddingTop="0" paddingLeft="0" paddingRight="0" borderStyle="solid" fontSize="8"/>
<mx:LinkButton label="GO" height="18" width="24" click="gopg();" paddingRight="0" paddingLeft="0" fontSize="8"/>
</mx:Box>
</mx:Module>
效果图如下:
调用方法:
1.初始化中需要设置RecordCount
pager.PageSize=Config.popPageSize;//设置页大小
getRecordCount(); //设置总记录条数
private function getRecordCount():void{
ProductBLL.GetRecordCount(function(e:ResultEvent):void{ //调用业务方法,获取记录条数
pager.setRecordCount(e.result as int); //设置记录条数
refData(); //获取数据
});
}
private function refData():void{
var start:int=pager.StartIndex; //记录开始值
ProductBLL.GetPageByName(start,pager.PageSize,function(e:ResultEvent):void{ //调用业务分页查询
dg1.dataProvider=e.result; //绑定数据
});
}
2.编写pageChanged事件,调用refData方法即可,如可直接写在标记中,如下:
<ns2:Pager x="10" y="324" width="504" id="pager" pageChanged="refData();"/> OK搞定!。