Extjs4本身的HtmlEditor编辑器,太鸡肋了,简单的html能够应付一下,稍加复杂的就无能为力了。

对于Extjs的HtmlEditor扩展主要有三个方向,一个是扩展其本身的htmlEditor,这个我在2.2的时候,扩展过几个功能,例如图片上传,附件添加等等,效果并不是特别理想http://hi.baidu.com/chinacloud/item/8c078fce9763027fced4f8d7

第二个方法一般初学者都会想到,用iframe内嵌一个编辑页面,这个方式我只想说:别糟蹋Extjs

第三个方法就是引用第三方的插件,要善于使用轮子,用轮子来造车,自然我选择第三种。

富文本框编辑器选择很多,但唯有KindEditor让我青睐已久,从最初的版本到现在的4.x,一直在用,小巧稳定,功能强大,配置简单等,除此之外可能百度的Editor也还不错,其他的就不敢说了。

下面开始整合Extjs4和Kindeditor,Extjs是一套非常优秀的RIA框架,能够非常方便的实现类的继承和扩展,我们新创建一个组建,继承textarea。

 Ext.define('WMC.common.view.ExtKindEditor', {
extend: 'Ext.form.field.TextArea',
alias: 'widget.extkindeditor',//xtype名称
initComponent: function () {
this.html = "<textarea id='" + this.getId() + "-input' name='" + this.name + "'></textarea>";
this.callParent(arguments);
this.on("boxready", function (t) {
this.inputEL = Ext.get(this.getId() + "-input");
this.editor = KindEditor.create('textarea[name="' + this.name + '"]', {
height: t.getHeight()-18,//有底边高度,需要减去
width: t.getWidth() - t.getLabelWidth(),//宽度需要减去label的宽度
basePath: '/Content/Plugin/kindeditor-4.1.5/',
uploadJson: '/Content/Plugin/kindeditor-4.1.5/asp.net/upload_json.ashx',//路径自己改一下
fileManagerJson: '/Content/Plugin/kindeditor-4.1.5/asp.net/file_manager_json.ashx',//路径自己改一下
resizeType: 0,
wellFormatMode: true,
newlineTag: 'br',
allowFileManager: true,
allowPreviewEmoticons: true,
allowImageUpload: true,
items: [
'source', '|', 'undo', 'redo', '|', 'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', '|',
'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'bold',
'italic', 'underline', 'lineheight', '|', 'image', 'multiimage',
'table', 'emoticons',
'link', 'unlink', 'fullscreen'
]
});
});
this.on("resize", function (t, w, h) {
this.editor.resize(w - t.getLabelWidth(), h-18);
});
},
setValue: function (value) {
if (this.editor) {
this.editor.html(value);
}
},
reset: function () {
if (this.editor) {
this.editor.html('');
}
},
setRawValue: function (value) {
if (this.editor) {
this.editor.text(value);
}
},
getValue: function () {
if (this.editor) {
return this.editor.html();
} else {
return ''
}
},
getRawValue: function () {
if (this.editor) {
return this.editor.text();
} else {
return ''
}
}
});

使用方法,和其他的field类似,如下:

//首先controller里要引用进来
Ext.define('WMC.controller.Main', {
extend: 'Ext.app.Controller',
.....
views: ['EditWin','WMC.common.view.ExtKindEditor'],
... //之后,在需要编辑的Window里,使用:
{
xtype: 'extkindeditor',
allowBlank: false,
name: 'Responsibilities',
height: 140,
width:670,
id: 'Responsibilities',
fieldLabel: '岗位职责'
}

然后界面就可以构造出来了

那么还剩一步,如何设置和获取extkindeditor的值呢?

//this.getSkills(),this.getResponsibilities()为refs中配置的get属性

//编辑
editRecord: function (view, record, item, index) {
var win = this.getEditWin();
var form = win.down("form");
form.loadRecord(record);
win.show();
//显示时候,将html的值显示到kindeditor中
this.getSkills().setValue(record.data.Skills);
this.getResponsibilities().setValue(record.data.Responsibilities);
},
//保存
saveRecord: function () {
var win = this.getEditWin();
var form = win.down("form");
var model = form.getValues();
//这里是重点,不设置的话,默认是非html格式的
model.Skills = this.getSkills().getValue();
model.Responsibilities = this.getResponsibilities().getValue(); if (form.isValid()) {
record = form.getRecord();
var store = this.getMainGrid().getStore();
if (record) {//如果是修改
record.set(model);
}
else {
store.add(model);
}
win.close();
store.sync();
}
},

OK,Enjoy It!

额。。。忘记了,不要忘记在页面head里加上引用:

<link href="~/Content/Plugin/kindeditor-4.1.5/themes/default/default.css" rel="stylesheet" />
<script src="~/Content/Plugin/kindeditor-4.1.5/kindeditor-all-min.js"></script>
<script src="~/Content/Plugin/kindeditor-4.1.5/lang/zh_CN.js"></script>

Extjs4.2x与富文本框编辑器KindEditor的整合的更多相关文章

  1. 富文本框编辑器实现:a、支持图片复制粘贴;b、支持word复制粘贴图文。

    Chrome+IE默认支持粘贴剪切板中的图片,但是我要发布的文章存在word里面,图片多达数十张,我总不能一张一张复制吧?Chrome高版本提供了可以将单张图片转换在BASE64字符串的功能.但是无法 ...

  2. wangEditor 轻量级富文本框编辑器使用方法

    首先第一步先去wangEditor官网下载所需要的脚本文件! http://www.wangeditor.com/ 接下来先在你的项目的HTML标签里加上这样一段标签: 1 <body> ...

  3. H5页面设计器,仿有赞商城页面在线设计器,比富文本框更友好的内容编辑器

    基本上每个web应用,都会牵扯到内容编辑,尤其是移动的web应用,微信开发之类的.页面内容自定义是最常用的功能了,之前大部分解决方案都是采用富文本框编辑器kindeditor,ueditor,cked ...

  4. webdriver高级应用- 操作富文本框

    富文本框的技术实现和普通的文本框的定位存在较大的区别,富文本框的常见技术用到了Frame标签,并且在Frame里面实现了一个完整的HTML网页结构,所以使用普通的定位模式将无法直接定位到富文本框对象. ...

  5. 常用的富文本框插件FreeTextBox、CuteEditor、CKEditor、FCKEditor、TinyMCE、KindEditor ;和CKEditor实例

    http://www.cnblogs.com/cxd4321/archive/2013/01/30/2883078.html 目前市面上用的比较多的富文本编辑器有: FreeTextBox 一个有很多 ...

  6. kindeditor富文本框,上传文件后,显示文件名称

    kindeditor作为一个应用广泛富文本框,我们经常会利用到它,然而在使用的过程中,发现有的地方使用起来很不方便,例如本文要说的,用户上传文件之后,默认只有文件URL,没有文件说明,如图: 点击确定 ...

  7. 使用kindeditor获取不到富文本框中的值

    获取不到富文本框中的值,网上一搜一堆,但最终没有几个能解决问题的,折腾一番最终解决.注意就是红色代码,加上之后就可以解决问题了. KindEditor.ready(function (K) { var ...

  8. kindeditor富文本框使用方法

    这周我一共使用了两个文本框编辑器!我的上一篇文档讲的是wangeditor这个编辑器,现在就来讲讲kindeditor这个编辑器! 首先还是去它的官网去下载脚本! http://kindeditor. ...

  9. 富文本HTML编辑器UEditor

    Baidu百度开源富文本HTML编辑器UEditor JS代码网 发表于: 2013-10-30 分类:HTML编辑器  点击:2133  UEditor是由百度web前端研发部开发所见即所得富文本H ...

随机推荐

  1. go语言学习-基础知识

    go程序的基本结构 一个可以最简单的可运行的go程序需要满足下面两个条件: 有一个main()函数 main()函数在main包中 例如: 在go语言中的 hello world 程序如下: // m ...

  2. CRC类(处理ITU表)

    class Crc { // CRC-ITU查找表 private static UInt16[] crctab16 = new UInt16[] { 0x0000, 0x1189, 0x2312, ...

  3. Problem E: 用链表实现约瑟夫环

    Description 你听说过约瑟夫问题吗?问题大致如下:首先n个人围成一个圈,标记为1到n号.接着,从1号开始报数(从1开始),然后2号报数,然后3号...当有人报到到m时,这个人就要踢出比赛,然 ...

  4. BZOJ4053 : [Cerc2013]Subway

    通过BFS可以求出到每个站点的最小花费. 每次从队首取出一个点,枚举所有它能花费1块钱就到达的线路,通过两遍递推求出最大时间. 注意到每个点和每条线路只有第一次使用时有用,所以总时间复杂度为$O(n+ ...

  5. bzoj 4128 矩阵求逆

    /************************************************************** Problem: 4128 User: idy002 Language: ...

  6. oracle 列相减——(Oracle分析函数Lead(),Lag())

    lag和lead函数,用于取出数据的前n行的数据和后n行的数据,当然要和over(order by)一起组合 其实这2个函数的作用非常好理解,Lead()就是取当前顺序的下一条记录,相对Lag()就是 ...

  7. 来自极客头条的 15个常用的javaScript正则表达式

    摘要收集整理了15个常用的javaScript正则表达式,其中包括用户名.密码强度.整数.数字.电子邮件地址(Email).手机号码.身份证号.URL地址. IPv4地址. 十六进制颜色. 日期. Q ...

  8. 前端AngularJS后端ASP.NET Web API上传文件

    本篇体验使用AngularJS向后端ASP.NET API控制器上传文件.    首先服务端: public class FilesController : ApiController { //usi ...

  9. android: 动态加载碎片布局的技巧

    虽然动态添加碎片的功能很强大,可以解决很多实际开发中的问题,但是它毕竟只是在 一个布局文件中进行一些添加和替换操作.如果程序能够根据设备的分辨率或屏幕大小在运 行时来决定加载哪个布局,那我们可发挥的空 ...

  10. crontab不能执行sudo:抱歉,您必须拥有一个终端来执行 sudo

    最近做一个可执行shell调度的需求,要求用户输入shell,然后后台定时调度运行.实现大致为:保存用户的输入,设定时间,crontab定时执行用户的输入.但这里涉及到一个安全问题,如何确定用户的输入 ...