双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

React刚开始用,遇到个分页的问题

student-ai student-ai 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
数据已经可以加载了,分页组件也加载出来了,只是分页操作点了不知道怎么触发查询(分页的时候需要把查询的参数带上。)


var PageInfo = React.createClass({
queryPageInfo:function(event){
/*var totalcount = this.props.totalcount;
var totalpage = this.props.totalpage;
var currentpage = this.props.currentpage;*/
var nextPage = event.target.dataset.currpagehref;
var currentIndex = this.props.currentIndex;
// console.log(currentIndex);
console.log(nextPage);
//if(currentIndex==1){//邮编查询地址.
/*

这里不知道怎么触发查询函数.
下面这个写法没效果.

想触发下面这个函数,触发查询:
findQueryPostCode

*/


this.setState({
currentpage:nextPage
});
//}
},
pageInfoGet:function(){
var totalpage = parseInt(this.props.totalpage);
var currentpage = parseInt(this.props.currentpage);
var rows = [];
for (var i = 0; i< totalpage; i++) {
if((i+1)==currentpage){
rows.push(<li className="am-active"><a data-currpagehref={i+1} onClick={this.queryPageInfo} href="javascript:void(0)">{i+1}</a></li>);
}else{
rows.push(<li><a data-currpagehref={i+1} onClick={this.queryPageInfo} href="javascript:void(0)">{i+1}</a></li>);
}
};
return rows;
},
render:function(){
return (
<ul className="am-pagination">
{this.pageInfoGet()}
</ul>
);
}
});

/* 表格展示数据 */
var Table = React.createClass({
display: function(){
var rows = [];
if(this.props.tableData && this.props.tableData.error_code=='0' ){
// console.log(this.props.tableData.result.totalcount);
// console.log(this.props.tableData.result.totalpage);
// console.log(this.props.tableData.result.currentpage);
this.props.tableData.result.list.forEach((item)=>{
rows.push(<tr><td>{item.Province}</td><td>{item.City}</td><td>{item.District}</td><td>{item.PostNumber}</td><td>{item.Address}</td></tr>)
})
}
return rows;
},
render: function(){
return (
<table className="ui-table">
<thead>
<tr>
<td>省(自治区)</td>
<td>市(直辖市/自治州)</td>
<td>区(县)</td>
<td>邮编</td>
<td>地址</td>
</tr>
</thead>
<tbody>{this.display()}</tbody>
</table>
);
}
});

let Tab = React.createClass({
render: function(){
return (<div>{this.props.children}</div>);
}
});

let TabsControl = React.createClass({
getInitialState: function(){
return {currentIndex: 0}
},

getTitleItemCssClasses: function(index){
return index === this.state.currentIndex ? "tab-title-item active" : "tab-title-item";
},

getContentItemCssClasses: function(index){
return index === this.state.currentIndex ? "tab-content-item active" : "tab-content-item";
},

render: function(){
let that = this;
let {baseWidth} = this.props;
let childrenLength = this.props.children.length;
return (
<div>
<nav className="tab-title-items">
{React.Children.map(this.props.children, (element, index) => {
return (<div onClick={() => {this.setState({currentIndex: index})}} className={that.getTitleItemCssClasses(index)}>{element.props.name}</div>)
})}
</nav>
<div className="tab-content-items">
{React.Children.map(this.props.children, (element, index) => {
return (<div className={that.getContentItemCssClasses(index)}>{element}</div>)
})}
</div>
</div>
)
}
});

/* div整体 */
var DIV = React.createClass({
findCityByProvinceId:function(provinceId){
var result = null;
if(provinceId){
cityListJson.forEach((province)=>{
if(province.id==provinceId){
result=province.city[0].id;
if(result){
return ;
}
}
});
}
return result;
},
provinceValue: function(){
var s = ReactDOM.findDOMNode(this.refs.ProvinceObj);
return s ? s.value : '-1';
},
cityValue: function(){
var s = ReactDOM.findDOMNode(this.refs.CityObj);
return s ? s.value : '-1';
},
opnProvinceChangeValue: function(){
this.setState({
provinceVal: this.provinceValue(),
cityVal: this.findCityByProvinceId(this.provinceValue())
});
},
onCityChangeValue: function(){
this.setState({
cityVal: this.cityValue()
});
},
find: function(){
this.setState({
message:"完善中,别闹......"
})
},
findQueryPostCode:function(){
var postCode = ReactDOM.findDOMNode(this.refs.queryPostCode);
var clickPageParam = this.props.currentpage?this.props.currentpage:this.state.currentpage;
if(postCode){
var resultDataAjax = null ;
$.ajax({
type:"POST",
url:"youbian.php",
data:{queryPostCode:postCode.value,page:clickPageParam},
dataType:"json",
async:false,
success:function(resultdata){
resultDataAjax = resultdata;
}
})
if(resultDataAjax && resultDataAjax.error_code=='0'){
var totalcount = resultDataAjax.result.totalcount;
var totalpage = resultDataAjax.result.totalpage;
var currentpage = resultDataAjax.result.currentpage;
this.setState({
tableData:resultDataAjax,
totalcount:totalcount,
totalpage:totalpage,
currentpage:currentpage
});
}
}
},
getInitialState: function(){
return ({
provinceVal: this.provinceValue(),
cityVal: this.cityValue(),
tableData:"",
totalcount:"",
totalpage:"",
currentpage:"1"
});
},
render: function(){
return (
<div>
<h1 style={{color:'red',fontSize:72}}>{this.state.message}</h1>
<TabsControl>
<Tab name="地址查询邮编">
<div>
<ProvinceObj ref="ProvinceObj" data={cityListJson} onChange={this.opnProvinceChangeValue} />
<CityObj ref="CityObj" data={cityListJson} provinceValue={this.state.provinceVal} onChange={this.onCityChangeValue} />
<CountyObj ref="CountyObj" data={cityListJson} provinceValue={this.state.provinceVal} cityValue={this.state.cityVal} />
<input type="text" ref="queryKey" maxLength="30" placeholder="请输入要搜索的数据..."/>
<button className="ui-button" onClick={this.find}>查找</button>
</div>
</Tab>
<Tab name="邮编查询地址">
<div> <input type="number" ref="queryPostCode" maxLength="30" placeholder="请输入邮编..."/>
<button className="ui-button" onClick={this.findQueryPostCode}>查找</button></div>
</Tab>
<Tab name="试试百度">
<div className="yellow"/>
</Tab>
</TabsControl>
<Table tableData={this.state.tableData}/>
<PageInfo totalcount={this.state.totalcount} totalpage={this.state.totalpage} currentpage={this.state.currentpage}/>
</div>
);
}
});
/* 渲染 */
var BODY1 = document.getElementById("BODY1");
ReactDOM.render(<DIV />, BODY1);




上面是一部分代码,已经放到服务器上了,可以访问12773.xyz,选择邮编查询地址即可,邮编可以输入:100023,谢谢!
...全文

相关推荐

react-paginate:创建分页的ReactJS组件

React分页 一个ReactJS组件来呈现分页。 通过安装此组件并编写少量CSS,您可以获得以下内容: 或者 安装 使用安装react-paginate : $ npm install react-paginate --save 对于用户: import ReactPaginate from 'react-paginate' ; 阅读的代码。 您将快速了解如何使对象在react-paginate工作。 演示版 克隆存储库并移至: $ git clone git@github.com:AdeleD/react-paginate.git $ cd react-paginate 安装依赖项: $ make install 准备演示: $ make demo 运行服务器: $ make serve 打开浏览器,然后转到 道具 姓名 类型 描述 pageCount N

槑可好

React的本地分页组件Reactjs-Pagination.zip

Reactjs-Pagination是一个React的本地分页组件,支持页码、跳转、和迷你模式。文档安装npm install --save reactjs-pagination使用示例代码:import React, { Component } from 'react'; import { Pagination }from 'reactjs-pagination';   class Test extends Component {     state = {         totalNumber: 326,         pageSize: 10,         currentPage: 31     };     constructor(props) {         super(props);         setTimeout(() => {             // this.setState({              //  currentPage: 15              // });              this.setState({                 totalNumber: 125             });         }, 3000);     }     handleChange = (idx) => {         console.log('页码改变 => ', idx);     }     render() {         const { totalNumber, pageSize, currentPage } = this.state;           return (             <div>                 <Pagination                     totalNumber={totalNumber}                     pageSize={pageSize}                     currentPage={currentPage}                     middlePage={5}                      标签:Reactjs

weixin_39840515

ContactViewer-ReactJS:这是一个简单的 React 组件,它以分页方式显示联系人列表

ContactViewer-ReactJS 这是一个简单的React组件,以分页的方式显示联系人列表。

weixin_42138139

一个创建分页的ReactJS组件-React开发

react-paginate一个ReactJS组件来呈现一个分页。 通过安装此组件并只编写少量CSS,您可以获得以下信息:或安装使用npm安装react-paginate:$ npm instal react-paginate一个ReactJS组件来呈现分页。 通过安装此组件并只编写少量CSS即可获得以下信息:或安装使用npm安装react-paginate:$ npm install react-paginate --save对于CommonJS用户:从'react-paginate'导入ReactPaginate; 阅读demo / js / demo.js的代码。 您将快速了解如何使对象在分页中工作。 演示克隆存储库并移至:$ git clone [受电子邮件保护]:Ad

八普

react-reactpaginate一个用于创建分页的ReactJS组件

react-paginate - 一个用于创建分页的ReactJS组件

weixin_39841848
评论 5
收藏 已收藏
分享
返回顶部
student-ai
JavaScript 87,983 成员 224,680 内容