遇到的问题是这样的,前台动态加载了checkboxgroup,刷新时候check没有被选中。而且form执行loadrecord方法时候,kindeditor中的内容加载不进去(没有动态加载就可以)。
找了很久才知道原因(但是不知道原理):
首先改,本来是afterrender
listeners : {
"render" : function(f) {
接下来修改这里:
items: [{
iconCls : 'icon-edit',
tooltip: '编辑',
handler: function(grid, rowIndex, colIndex, item) {
var rec = grid.getStore().getAt(rowIndex);
var formWin = Ext.create("Sharera.view.web.Document.FormEdit",{bid:rec.data.id});
var formObj=formWin.down('form').getForm();
formWin.show();
var opt={errorReader : Ext.create('Sharera.system.FormErrorReader')};
Ext.apply(formObj,opt);
var fstore = Ext.create("Sharera.store.web.Documentform");
fstore.setUrlforForm(rec.data.id);
fstore.load(
{
scope: this,
callback: function(records, operation, success) {
var data=records[0].data;
//console.debug(data);
formObj.findField("title").setValue(records[0].data.title);
formObj.findField("creator").setValue(records[0].data.creator);
formObj.findField("summary").setValue(records[0].data.summary);
formObj.findField("content").setValue(records[0].data.content);
//formObj.loadRecord(records[0]);
}
}
);
这个时候不能使用loadrecord,直接手动赋值。
好了,看效果:
kindeditor代码:
Ext.define('', {
extend:'Ext.form.field.TextArea',
alias : 'widget.kindeditorfield',
maxLength : '1000',
height : 250,
bid:'',
baseUrl:'',
name : '',
initComponent: function() {
var self=this;
Ext.apply(this, {
constructor: function(cfg) {
this.callParent();
this.initConfig(cfg);
},
maxLength : '1001',
height : 250,
maxLengthText : '文章提示信息长度不能超过2000字',
anchor : '100%',
listeners : {
"render" : function(f) {
K = KindEditor;
console.debug(self.bid+'kind');
this.editor = K.create('textarea[name="' + this.name + '"]',{
uploadJson : self.baseUrl+'/'+self.bid+'/upload',//
fileManagerJson :self.baseUrl+'/'+self.bid+'/files',//
height : 250,
width : 670,
fontSizeTable:['21px','20px','17px','18px','16px','14px','12px'],
resizeType : 1,
allowPreviewEmoticons : true,
allowImageUpload : true,
allowFileManager : true,
//items : ['source', '|', 'undo', 'redo', '|', 'preview', 'print', '|', 'selectall', '|', 'fullscreen', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'flash', 'media', 'table', 'hr', 'emoticons', 'pagebreak', 'anchor', 'link', 'unlink']
syncType: "auto"
});
this.editor.html('');
console.debug(this.editor);
}
},
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.html(value);
}
},
getValue : function() {
if (this.editor) {
return this.editor.html();
} else {
return ''
}
},
getRawValue : function() {
if (this.editor) {
return this.editor.html();
} else {
return ''
}
}
});
this.callParent(arguments);
}
});
formedit代码:
{
xtype: 'checkboxgroup',
fieldLabel: '城市',
vertical: true,
allowBlank :true,
items: [],
listeners:{
render:function(view, opt){
var cbg=this;
var cityCheckBoxs=new Array();//生成一个空数组用来装所有的城市对象
//console.debug(view);
var t=this;
Ext.Ajax.request({
async:false, //设置同步
url:'../api/city/param/list.json?id='+self.bid,//请求路径,需要手动输入指定
method:'get',
success: function(response){
var citys=eval('('+response.responseText+')');
for(var j=0;j<citys.length;j++){
cbg.items.add(
new Ext.form.Checkbox({
checked:citys[j].checked,
boxLabel: citys[j].value,
inputValue: citys[j].id,
name: 'city' ,//这个是后台接收的表单域,这里的checkboxgroup都使用同一个name
id:citys[j].id
}));
}
cbg.doLayout();
}
})
}
}},{
xtype: 'checkboxgroup',
fieldLabel: '标签',
vertical: true,
allowBlank :true,
items: [],
listeners:{
render:function(view, opt){
var cbg=this;
var tagCheckBoxs=new Array();//生成一个空数组用来装所有的标签对象
//console.debug(view);
var t=this;
Ext.Ajax.request({
async:false, //设置同步
url:'../api/documenttag/param/list.json?id='+self.bid,//请求路径,需要手动输入指定
method:'get',
success: function(response){
var tags=eval('('+response.responseText+')');
for(var j=0;j<tags.length;j++){
cbg.items.add(
new Ext.form.Checkbox({
checked:tags[j].checked,
boxLabel: tags[j].tagName,
inputValue: tags[j].id,
name: 'documentTag', //这个是后台接收的表单域,这里的checkboxgroup都使用同一个name
id:tags[j].id
}));
}
cbg.doLayout();
}
})
}
}},
{fieldLabel:'正文',name :'content',xtype:'kindeditorfield',bid:this.bid,baseUrl:this.baseUrl},
]
grid中的代码:
header:'操作',
align: 'center',
xtype:'actioncolumn',
width:70,
items: [{
iconCls : 'icon-edit',
tooltip: '编辑',
handler: function(grid, rowIndex, colIndex, item) {
var rec = grid.getStore().getAt(rowIndex);
var formWin = Ext.create("Sharera.view.web.Document.FormEdit",{bid:rec.data.id});
var formObj=formWin.down('form').getForm();
formWin.show();
var opt={errorReader : Ext.create('Sharera.system.FormErrorReader')};
Ext.apply(formObj,opt);
var fstore = Ext.create("Sharera.store.web.Documentform");
fstore.setUrlforForm(rec.data.id);
fstore.load(
{
scope: this,
callback: function(records, operation, success) {
var data=records[0].data;
//console.debug(data);
formObj.findField("title").setValue(records[0].data.title);
formObj.findField("creator").setValue(records[0].data.creator);
formObj.findField("summary").setValue(records[0].data.summary);
formObj.findField("content").setValue(records[0].data.content);
//formObj.loadRecord(records[0]);
}
}
);
var b=formWin.down("button[ref='save'] ");
var store = grid.getStore();
b.on("click", function(){
if (formObj.isValid()) {
formObj.submit({
waitTitle : '发送数据',
waitMsg : '正在保存...',
timeout : 1000,
success : function(form, action) {
Ext.Sharera.msg("提示",'修改成功');
formWin.close();
store.reload();
},
failure : function(form, action) {
Ext.Sharera.error("错误",'修改失败');
formWin.close();
}
});
}
}, this);
}
},{iconCls : '',
tooltip: ''
},{
iconCls : 'icon-checkininfo',
tooltip: '查看',
handler: function(grid, rowIndex, colIndex, item) {
var rec = grid.getStore().getAt(rowIndex);
var formWin= Ext.create("Sharera.view.web.Document.FormDisplay");
var formObj=formWin.down('form').getForm();
var fstore = Ext.create("Sharera.store.web.Documentform");
fstore.setUrlforForm(rec.data.id);
fstore.load(
{
scope: this,
callback: function(records, operation, success) {
formObj.loadRecord(records[0]);
var city=records[0].data.city;
var cityName=new Array();
for(var i=0;i<city.length;i++){
cityName.push(city[i].city.value);
}
console.debug(records[0]);
formObj.findField('city').setValue(cityName.join(','));
var tag=records[0].data.tag;
var tagName=new Array();
for(var i=0;i<tag.length;i++){
tagName.push(tag[i].tag.tagName)
}
formObj.findField('tag').setValue(tagName.join(','));
}
}
);
}
}]