本文目錄一覽:
- 1、關於Extjs 中htmlEditor的問題,怎麼動態的在htmleditor初始化時賦值,默認值就不要了
- 2、Extjs4.0如何限制的htmleditor的輸入長度,具體的方法
- 3、extjs中HtmlEditor怎樣使用,
- 4、extjs 3.4中 怎麼給htmlEdit添加圖片插件 實現圖片上傳功能
- 5、ExtJs htmleditor如何設置不顯示工具欄?
關於Extjs 中htmlEditor的問題,怎麼動態的在htmleditor初始化時賦值,默認值就不要了
你好,Ext一般都是讀取json格式數據。htmlEditor屬於Ext form表單里的,所以我找到了以前做的一個關於form賦值的代碼例子給你貼出來,希望你能有所啟示。 代碼格式可能有點亂,不過你要相信一點,Ext處理數據一般都會用store。。。還有不懂的話隨時問e…..加油哈
註: 重點關注 下面items項內容
function editDept() {
var fp = new Ext.FormPanel({
frame : true,
border : 0,
items : [{
fieldLabel : ‘緊急程度’,
xtype : “combo”,
store : new Ext.data.JsonStore({
fields : [“id”, ‘text’, ‘value’],
idProperty : ‘id’,
data : [{ //這裡的數據可以通過Ext ajax與後後台聯繫,讀取後台數據
id : ‘c0’,
text : ‘清除’,
value : 0
}, {
id : ‘c1’,
text : ‘img src=”../images/dwbj.gif”‘,
value : 1
}, {
id : ‘c2’,
text : ‘img src=”../images/dwbj.gif”img src=”../images/dwbj.gif”‘,
value : 2
}]
}),
valueField : ‘id’,// 值,可選
displayField : ‘text’,// 顯示文本
mode : ‘local’,
forceSelection : true,// 必須選擇一項
triggerAction : ‘all’,// 因為這個下拉是只能選擇的,所以一定要設置屬性triggerAction為all,不然當你選擇了某個選項後,你的下拉將只會出現匹配選項值文本的選擇項,其它選擇項是不會再顯示了,這樣你就不能更改其它選項了。
editable : false,// 不允許輸入
selectOnFocus : true,
width : 200,
id : ‘wenshu’,
listeners : {
‘select’ : function(combo, srecord, indexss) {
var array = Ext.getCmp(‘mygrid’).getSelectionModel()
.getSelections();
var ids = “”;
for (var i = 0; i array.length; i++) {
ids += array[i].get(‘sginfo.sgid’) + “,”;
}
Ext.Ajax.request({
url : “sgJyInfo!updJjd.action”,
params : {
“jjd” : srecord.get(“value”),
“sgids” : ids
},
callback : function(options, success, response) {
var v = Ext.util.JSON.decode(response.responseText);
if (v.suc) {
for (var i = 0; i array.length; i++) {
array[i].set(‘jjd’, srecord.get(“value”));
};
_win.close();
} else {
Ext.Msg.alert(“提示”, v.msg);
}
}
});
}
}
}]
})
var _win = new Ext.Window({
title : “修改處理情況”,
height : 83,
modal : true,
width : 370,
// iconCls : _iconCls,
id : “edit_win”,
bodyStyle : ‘padding:5px 5px’,
items : [fp]
});
_win.show();
}
Extjs4.0如何限制的htmleditor的輸入長度,具體的方法
htmleditor 沒有相應的屬性限制長度。
只能是輸入完之後,提交的時候驗證一下。
這個不用給你寫了吧? 還是寫一下吧。。
var htmleditor = new Ext.form.field.HtmlEditor({…..});
if(htmleditor.getValue().length 100){
Ext.Msg.alert(‘提示’, ‘不能超出100字符’);
return;
}
extjs中HtmlEditor怎樣使用,
var descriptionHtmlEditor = new Ext.form.HtmlEditor({
id:’dhtml’,
name: ‘description’,
allowBlank:true,
width:590,
height:450
})
var fpmu=new Ext.form.FormPanel({
border:false,
width:350,
frame:true,
autoHeight:true,
layout:’form’,
border:false,
items:[descriptionHtmlEditor]
})
var win = new Ext.Window({
title : ‘窗口’,
closeAction : ‘hide’,
layout:’fit’,
width : 750,
height : 360,
resizable : false,
modal : true,
items:[fpmu],
buttons:[{text:’提交’,handler:function(){
fpmu.getForm().submit({
url:’test.aspx?cmd=htmleidtor’,
method:’post’,
waitMsg:’正在上傳文件中…’,
// params:{he:Ext.state.Manager.get(“cun”)},
success:function(descriptionHtmlEditor,o){
// Ext.Msg.alert(‘提示’,o.result.message);
if(o.result.message==’上傳成功’){
}
},
failure:function(descriptionHtmlEditor,o){
Ext.Msg.alert(‘信息’,’操作失敗!’+ o.result.error);
}
})
}}]
});
win.show();
測試通過,FIREBUG有POST值到後台。
extjs 3.4中 怎麼給htmlEdit添加圖片插件 實現圖片上傳功能
首先要使用extjs自帶的HTMLEditor,然後在原有的工具條上添加一個圖片按鈕,點擊這個圖片按鈕要彈出窗口,這個窗口負責實現上傳功能,實現上傳後,要將上傳的圖片路徑添加到 HTMLEditor 的光標處,並且要以IMG/IMG的方式,這樣 HTMLEditor 才能解析出來。實現代碼如下:
前台JSP頁面
fieldLabel : ‘商品特性’,
id : ‘shopSp.spTxms’,
name : ‘shopSp.spTxms’,
xtype : ‘StarHtmleditor’,
anchor : ‘93%’
這其中引用了StarHtmleditor,StarHtmleditor.js的代碼如下,直接將代碼複製下來,然後新建個JS,全複製進去就行了。
var HTMLEditor = Ext.extend(Ext.form.HtmlEditor, {
addImage : function() {
var editor = this;
var imgform = new Ext.FormPanel({
region : ‘center’,
labelWidth : 55,
frame : true,
bodyStyle : ‘padding:5px 5px 0’,
autoScroll : true,
border : false,
fileUpload : true,
items : [{
xtype : ‘textfield’,
fieldLabel : ‘選擇文件’,
id : ‘UserFile’,
name : ‘UserFile’,
inputType : ‘file’,
allowBlank : false,
blankText : ‘文件不能為空’,
anchor : ‘90%’
}],
buttons : [{
text : ‘上傳’,
handler : function() {
if (!imgform.form.isValid()) {return;}
imgform.form.submit({
waitMsg : ‘正在上傳……’,
url : ‘HTMLEditorAddImgCommonAction.action’,
success : function(form, action) {
var element = document.createElement(“img”);
element.src = action.result.fileURL;
if (Ext.isIE) {
editor.insertAtCursor(element.outerHTML);
} else {
var selection = editor.win.getSelection();
if (!selection.isCollapsed) {
selection.deleteFromDocument();
}
selection.getRangeAt(0).insertNode(element);
}
//win.hide();//原始方法,但只能傳一個圖片
//更新後的方法
form.reset();
win.close();
},
failure : function(form, action) {
form.reset();
if (action.failureType == Ext.form.Action.SERVER_INVALID)
Ext.MessageBox.alert(‘警告’,’上傳失敗’,action.result.errors.msg);
}
});
}
}, {
text : ‘關閉’,
handler : function() {
win.close(this);
}
}]
})
var win = new Ext.Window({
title : “上傳圖片”,
width : 300,
height : 200,
modal : true,
border : false,
iconCls : “picture.png”,
layout : “fit”,
items : imgform
});
win.show();
},
createToolbar : function(editor) {
HTMLEditor.superclass.createToolbar.call(this, editor);
this.tb.insertButton(16, {
cls : “x-btn-icon”,
icon : “picture.png”,
handler : this.addImage,
scope : this
});
}
});
Ext.reg(‘StarHtmleditor’, HTMLEditor);
JS的第一句 var HTMLEditor = Ext.extend(Ext.form.HtmlEditor, 網上是沒有var的,不用var不知道為什麼總是報錯,另外JS一定要與JSP的編碼方式一致,要不然報莫名其妙的錯誤,而且錯誤都沒有顯示。
後台java代碼
/****
* HTMLEditor增加上傳圖片功能:
* 1、上傳圖片後,需要將圖片的位置及圖片的名稱返回給前台HTMLEditor
* 2、前台HTMLEditor根據返回的值將圖片顯示出來
* 3、進行統一保存
* @param 上傳圖片功能
* @return JSON結果
* @throws IOException
*/
public void HTMLEditorAddImg() throws IOException {
if(!””.equals(UserFile) UserFile != null UserFile.length() 0){
File path = ImportImg(UserFile, “jpg”);
UserFilePath = “../” + path.toString().replaceAll(“\\\\”, “/”).substring(path.toString().replaceAll(“\\\\”, “/”).indexOf(“FileImg”));
}
this.getResponse().setContentType(“text/html”);
this.getResponse().getWriter().write(“{success:’true’,fileURL:'” + UserFilePath + “‘}”);
}
特別要注意的是路徑問題,路徑問題主要有2點需要注意:
1、前台頁面引用 StarHtmleditor.js 的路徑一定要正確;
2、 Htmleditor上傳的圖片路徑一定要改,因為上傳之後圖片路徑變為,在正常使用中圖片不顯示,要將該地址替換為服務器的IP地址;替換方法如下:
//獲取本地IP地址,因為extjs的htmleditor上傳的照片路徑有問題,需要將路徑替換為本機IP地址
InetAddress inet = InetAddress.getLocalHost();
shopSp.setSpTxms(shopSp.getSpTxms().replace(“localhost”, inet.getHostAddress().toString()));
這樣基本就完成了這個HTMLEditor上傳圖片功能。
如圖:
ExtJs htmleditor如何設置不顯示工具欄?
enableFont : Boolean
允許字體選項。Safari 中無效。(默認為 true)。Enable… 允許字體選項。Safari 中無效。(默認為 true)。Enable font selection. Not
available in Safari. (defaults to true) HtmlEditor
enableFontSize : Boolean
允許增大/縮小字號按鈕(默認為 true)。Enable the in… 允許增大/縮小字號按鈕(默認為 true)。Enable the increase/decrease font size
buttons (defaults to true) HtmlEditor
enableFormat : Boolean
允許粗體、斜體和下劃線按鈕(默認為 true)。Enable the … 允許粗體、斜體和下劃線按鈕(默認為 true)。Enable the bold, italic and underline
buttons (defaults to true) HtmlEditor
enableLinks : Boolean
允許創建鏈接按鈕。Safari 中無效。(默認為 true)。Enab… 允許創建鏈接按鈕。Safari 中無效。(默認為 true)。Enable the create link button.
Not available in Safari. (defaults to true) HtmlEditor
enableLists : Boolean
允許項目和列表符號按鈕。Safari 中無效。(默認為 true)。E… 允許項目和列表符號按鈕。Safari 中無效。(默認為 true)。Enable the bullet and numbered
list buttons. Not available in Safari. (defaults to true) HtmlEditor
enableSourceEdit :
Boolean
允許切換到源碼編輯按鈕。Safari 中無效。(默認為 true)。E… 允許切換到源碼編輯按鈕。Safari 中無效。(默認為 true)。Enable the switch to source
edit button. Not available in Safari. (defaults to true) HtmlEditor
fieldClass : String 表單元素一般狀態CSS樣式(默認為”x-form
快快把分給我…
原創文章,作者:XYDW,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/142981.html