一个非常奇怪但是解决后不知道为何的问题。
2013-07-24 18:17
423 查看
遇到的问题是这样的,前台动态加载了checkboxgroup,刷新时候check没有被选中。而且form执行loadrecord方法时候,kindeditor中的内容加载不进去(没有动态加载就可以)。
找了很久才知道原因(但是不知道原理):
首先改,本来是afterrender
接下来修改这里:
这个时候不能使用loadrecord,直接手动赋值。
好了,看效果:
kindeditor代码:
formedit代码:
找了很久才知道原因(但是不知道原理):
首先改,本来是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(',')); } } ); } }]
相关文章推荐
- 关于Qt编译时问题的一个非常奇怪的解决方法
- 遇到的一个SCOM怪问题,虽然解决但是不知道为什么
- 解决一个问题的思路 之“解决已经写满con.close() 仍然出现"但是尚未从池中获取连接"的连接池耗尽问题”
- 一个奇怪网络问题的解决:执行sql时客户端卡死
- 小小问题集锦6之---查询条件非常复杂时解决效率不高的一个办法
- Delphi中TStringlist.count一个奇怪问题及其解决
- zz 关于一个flex 加 SFS的配置 但是我自己没有测试出来 那个SFSEvent报错 不知道有没有人能解决
- HBase的一个非常恶心的问题---create失败的解决办法
- 给定一个单链表,从链表返回一个随机节点的值。 每个节点必须具有相同的选择概率。 跟进: 如果这个链表非常大,而且它的长度不为人知呢? 你能解决这个问题,而不使用额外的空间?
- 解决mantis2.4.0 htmlentities只能是字符串但是传入一个数组的问题
- 调试PCB板中,结果短路了,这是一个非常纠结的问题,写下解决经验
- tomcat发现一个奇怪的问题,如我在本地tomcat发布了一个工程testProject,输入127.0.0.1:8080/testProject登录了,但是输入:本机ip地址:8080/testP
- 安装Piwik时遇到的一个奇怪的关于PHP参数问题的解决办法
- 一个非常奇怪的问题,高手请进!!(在线等。。。。。)
- atmel studio遇到的USART问题,解决了,但是不知道问题所在
- 临时表中一个非常奇怪的问题
- 蓝牙和wifi的一个奇怪问题之解决
- 【转】一个非常常见但容易被忽略的c++问题——用IPML模式可以解决
- 最近碰到一个奇怪有不容易解决的问题,总算搞定!
- 蓄水池抽样(Reservoir sampling)解决在不知道样本容量的情况下随机抽取一个或多个元素的问题