做了两个extjs的独立元件

十二 04 2009 Published by zdy under 杂七杂八

又一个通宵,整整一个晚上,才做好两个extjs3.0的组件,一个是批量移动照片的窗口(chooser),还有一个就是批量上传,上传用的swfupload。其中大部分时间花在了swfupload上,在gridpanel中加入ProgressBar真的比较麻烦,自己没想出,但是发现官网论坛上有人写出了方法,确实简单。
总之,记点笔记,免得忘了。
1.关于store的

//添加一条数据,
var u =new this.store.recordType({
	name : this.fileProgressName,
	fileid: this.fileProgressID,
	size : file.size,
	jindu : '0',
	filestatus : 0
});
this.store.add(u);
//find方法得到id
this.index = this.store.find('fileid',this.fileProgressID);
//如果需要这条数据的话
var record=this.store.getAt(this.index);
//修改指定格的值
record.set('jindu', '1');

2.然后是表格中放入其他object。ProgressBar什么的应该都可以

renderer:function change(value, meta, rec, row, col, store){
	var id = Ext.id();
	(function(){
		new Ext.ProgressBar({
			id:rec.data.fileid+'-jd',
			renderTo: id,height:13,
			value: value,
		})
	}).defer(25);
	return '<span id="' + id + '"></span>';
}

这个有个缺陷就是如果动态更新表格内容,里面可能会重复出现ProgressBar,所以最好就是使用指定id,
然后检查是存在,存在就删了,然后生成新的,不然比较麻烦。
用extjs真的是个体力活,要不停的查看api document

No responses yet

javascript循环调用函数,函数中监听事件只执行最后一个bug

十一 30 2009 Published by zdy under 编程技巧

在使用javascript的时候发现一个问题,
循环调用一个函数a,在函数a每次被调用时使用addEventListener给一个新的元素添加事件,但是经测试后发现每次只有最后一次调用函数a时产生的事件可以使用
最后发现添加window. setTimeout可以解决问题

FileProgress.prototype.toggleCancel = function (show, swfuploadInstance) {
	this.showcss =  show ? &quot;visible&quot; : &quot;hidden&quot;;
	$(&quot;s_l_s_a_&quot;+this.fileProgressID).style.visibility=this.showcss;
	if (swfuploadInstance) {
		var fileID = this.fileProgressID;
		window.setTimeout(function(){
			$(&quot;s_l_s_a_&quot;+fileID).addEventListener('click',function(){
				swfuploadInstance.cancelUpload(fileID);
				return false;
			},false);
		},1000);
	}
};

这部分代码是用在swfupload上传中的,以前本来是用jquery做的,但是最近想把这个模块用到Extjs中,想想还是不使用外部组件,这样以后想用在哪里都可以

No responses yet