React.js官网的评论列表
来源:互联网 发布:mac上的音频剪辑软件 编辑:程序博客网 时间:2024/04/28 01:53
container--------------commentBox 评论列表----commentList 评论内容---comment 评论内容---comment 评论列表---- 写评论的组件---commentFormcontainer--------------1.获取评论数据(1)在服务端写mock模拟数据--取得API接口的URL地址(2)在对应函数内写ajax请求,在success中this.setState({data:result.*})不要忘记 getInitialState: function() { return {data: []}; },(3)在评论组件中循环遍历data<CommentList data={this.state.data} />var CommentList = React.createClass({ render: function() { var commentNodes = this.props.data.map(function(comment) { return ( <Comment author={comment.author} key={comment.id}> {comment.text} </Comment> ); }); return ( <div className="commentList"> {commentNodes} </div> ); }});2.添加评论(1)给每一个输入框,下拉框,分页等设置 onChange={this.*} getInitialState: function() { return {author: '', text: ''}; },(2) handleTextChange(e){ handleTextChange就是* 对应输入框等的改变事件 this.setState({text: e.target.value});}(3)在提交表单的事件中判断数据是否为空,数据的长度同时将输入框的数据清空 handleSubmit: function(e) { 对应form组件的提交事件 e.preventDefault(); var author = this.state.author.trim(); var text = this.state.text.trim(); if (!text || !author) { return; } // TODO: send request to the server this.setState({author: '', text: ''}); },(4)通过ajax请求发送数据最顶层--------------- handleCommentSubmit: function(comment) { $.ajax({ url: this.props.url, dataType: 'json', type: 'POST', data: comment, success: function(data) { this.setState({data: data}); }.bind(this), error: function(xhr, status, err) { console.error(this.props.url, status, err.toString()); }.bind(this) }); },<CommentForm onCommentSubmit={this.handleCommentSubmit} />在CommentForm组件内------------ this.props.onCommentSubmit({author: author, text: text});
0 0
- React.js官网的评论列表
- React.js 官网资料摘记:列表&keys
- React-基于React & Reflux 的评论框组件 (ES6)
- 评论列表
- React Js 仿京东物流列表查询
- 评论列表数据数据重复的问题
- react native 仿微信朋友圈的评论自动定位
- 写给 Rapid D3.js 的评论
- 使用js实现用户评论的星级
- 基于react实现一个简单的评论框/留言板React-messageboard
- [OK]ECSHOP商品列表页显示每个商品的评论等级和评论数量
- 在ECSHOP商品列表页显示每个商品的评论等级和评论数量
- 在ECSHOP模板商品列表页 显示商品的评论等级和评论数量
- 用 JSON 实现侧边栏的最新评论列表
- 我根据水果列表改的微博评论
- 根据水果列表改的微博评论
- CommentListTextView 一个TextView实现朋友圈的评论列表
- react native 列表展示的解决方案
- HTTP学习笔记:状态码
- 神经网络训练中的Tricks之高效BP(反向传播算法)
- CentOS7 (精简操作指令)
- Edit Distance
- # dagger+retrofit+rxjava:框架搭建视频播放器:
- React.js官网的评论列表
- C语言动态内存管理
- win7激活一万遍都没解决的同学请看过来
- Android 中横屏竖屏设置
- dokan入门编译指南
- social-feed-box 社会评论模块(Bootstrap)
- 有思想的大脑,没灵性的AI
- 在Spring Boot中使用数据库事务
- 类型转换和符号扩展,again!