React中使用UEditor
一般UEditor用于表单的新建和编辑
<FormItem {...formItemLayout} label='商品详情'>
{getFieldDecorator('detail', {
rules: [{ required: true, message: '请输入商品详情' }]
})(<Ueditor width={692} id="detail" toolbars={videoToolbar} />)}
</FormItem>
id和name要相同
表单提交的时候校验详情是否输入 (因为form.getFieldValue('detail')拿到的值是‘contentChange’,不能作为是否为空的凭证)
if (!getContent('detail')) {
form.setFields({
detail: {
value: getContent('detail'),
errors: [new Error(`请输入${type == 1 ? '音频' : '视频'}详情`)]
}
})
}
编辑的时候,需要将内容写入UEditor
edit:是否是编辑页 如果是新建页就不用写入
hasDetail:是否已经渲染好了detail componentWillReceiveProps会执行好几次 如果不判断是否已经渲染好了detail editor.ready会进入死循环
courseDetail.detail:渲染的数据
componentDidMount和componentWillReceiveProps都要执行相同的步骤 因为在实践过程中发现有少数情况 在进入编辑页或者刷新编辑页时editor不能被成功渲染
componentDidMount() {
const { courseDetail, edit, hasDetail, dispatch } = this.props
if (courseDetail.detail && edit && !hasDetail) {
const editor = getUeditor('detail')
editor.ready(function() {
dispatch({
type: 'courseManagement/saveHasDetail',
payload: true
})
editor.setContent(courseDetail.detail)
})
}
}
componentWillReceiveProps(nextProps) {
const { courseDetail, edit, hasDetail, dispatch } = nextProps
if (courseDetail.detail && edit && !hasDetail) {
const editor = getUeditor('detail')
editor.ready(function() {
dispatch({
type: 'courseManagement/saveHasDetail',
payload: true
})
editor.setContent(courseDetail.detail)
})
}
}
React中使用UEditor的更多相关文章
- 理解React中es6方法创建组件的this
首发于:https://mingjiezhang.github.io/(转载请说明此出处). 在JavaScript中,this对象是运行时基于函数的执行环境(也就是上下文)绑定的. 从react中的 ...
- 【原】React中,map出来的元素添加事件无法使用
在使用react中,经常用到react的map函数,用法和jquery里中的map一样,但是,如果你在每个map出来的元素中添加,你会发觉添加的事件无法关联, 比如,我们很多的评论,我需要在每个评论下 ...
- React中props.children和React.Children的区别
在React中,当涉及组件嵌套,在父组件中使用props.children把所有子组件显示出来.如下: function ParentComponent(props){ return ( <di ...
- asp.net中使用ueditor
原文地址:http://blog.uoolo.com/Article/16 还有在MVC中使用ueditor:http://blog.uoolo.com/Article/111 最初百度了一下“编辑器 ...
- Immutable 详解及 React 中实践
本文转自:https://github.com/camsong/blog/issues/3 Shared mutable state is the root of all evil(共享的可变状态是万 ...
- React中父组件与子组件之间的数据传递和标准化的思考
React中父组件与子组件之间的数据传递的的实现大家都可以轻易做到,但对比很多人的实现方法,总是会有或多或少的差异.在一个团队中,这种实现的差异体现了每个人各自的理解的不同,但是反过来思考,一个团队用 ...
- React中使用CSSTransitionGroup插件实现轮播图
动画效果,是一个页面上必不可少的功能,学习一个新的东西,当然就要学习,如何用新的东西,用它的方法去实现以前的东西啦.今天呢,我就在这里介绍一个试用react-addons-css-transition ...
- 在React中使用Redux
这是Webpack+React系列配置过程记录的第六篇.其他内容请参考: 第一篇:使用webpack.babel.react.antdesign配置单页面应用开发环境 第二篇:使用react-rout ...
- React中的路由系统
React中的路由系统 提起路由,首先想到的就是 ASPNET MVC 里面的路由系统--通过事先定义一组路由规则,程序运行时就能自动根据我们输入的URL来返回相对应的页面.前端中的路由与之类似,前端 ...
随机推荐
- poj1961 & hdu1358 Period【KMP】
Period Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 20436 Accepted: 9961 Descripti ...
- Solutions for common Android development problems with the Eclipse IDE- Tutorial
Table of Contents 1. Solving typical Android development problems 1.1. Clean Project 1.2. android.co ...
- UIWebView中加载的网页尺寸太大,如何让网页适应屏幕大小 WebView加载HTML图片大小自适应与文章自动换行
webview.scalesPageToFit = YES; http://www.cnblogs.com/yujidewu/p/5740934.html 若需要根据图片原本大小,宽度小于320px的 ...
- HTTPS握手
作用 内容加密 建立一个信息安全通道,来保证数据传输的安全: 身份认证 确认网站的真实性 数据完整性 防止内容被第三方冒充或者篡改 https的采用了对称加密和非对称加密.握手过程中采用非对称加密,得 ...
- Buy Tickets---poj2828(线段树)
题目链接:http://poj.org/problem?id=2828 题意就是有n个x y每次都是把y放到x位置,如果x位置有数,则把该位置之后的数往后放一位: [题解]: 线段树节点中保存这一段中 ...
- 利用GridView实现单选效果
1.实现如图所示的单选效果 由于Android提供的单选按钮radiobutton只能单行或单列显示,且样式并不美观,故可用GridView进行改造,实现单选效果,而要实现这样的效果重点就在GridV ...
- 解决Eclipse中新建jsp文件总是以ISO8859-1编码问题
eclipse --> window -->Preferences-->web-->jsp-->utf-8
- android 控件加圆角
1.新建一个radius_border.xml <shape xmlns:android="http://schemas.android.com/apk/res/android&quo ...
- java-mybaits-00201-DAO-SqlSession使用范围
1.SqlSession的使用范围 SqlSession中封装了对数据库的操作,如:查询.插入.更新.删除等. 通过SqlSessionFactory创建SqlSession,而SqlSessionF ...
- PID参数调整的口诀
PID参数调整的口诀:参数整定找最佳,从小到大顺序查先是比例后积分,最后再把微分加曲线振荡很频繁,比例度盘要放大曲线漂浮绕大湾,比例度盘往小扳曲线偏离回复慢,积分时间往下降曲线波动周期长,积分时间再加 ...