首页 > Dhtmlx > dhtmlxVault中文学习资料

dhtmlxVault中文学习资料

Initialize object on page

<div id="vaultDiv"></div>
vault = new dhtmlXVaultObject();
vault.setImagePath("codebase/imgs/");
vault.setServerHandlers("UploadHandler.php", "GetInfoHandler.php",
		"GetIdHandler.php");
vault.setFilesLimit(1);// 控制文件的上传数量:0不限制,1只能是一个
// 检测文件的上传类型
vault.onAddFile = function(fileName) {
	var ext = this.getFileExtension(fileName);
	if (ext != "txt" && ext != "doc") {
		alert("You may upload only text documents "
				+ "(txt, doc). Please retry.");
		return false;
	} else {
		return true;
	}
};

//Use onUploadComplete event handler to update your DhtmlX controls or check the upload status.
回调函数(对所有上传文件的处理)

vault.onUploadComplete = function(files) {
	var s=""; 
	for (var i=0; i<files.length; i++) {
		var file = files[i];
		s += ("id:" + file.id + ",name:" + file.name + ",uploaded:" + 
				file.uploaded + ",error:" + file.error)+"\n"; 
	} 
	alert(s);
};

//Use onFileUploaded event handler to react on every particular file uploaded.
//对某一文件的处理

vault.onFileUploaded = function(file) {
 alert("id:" + file.id + ",name:" + file.name + ",uploaded:" + 
		 file.uploaded + ",error:" + file.error); 
};
vault.create("vaultDiv"); 
//Use setFormField(fieldName,value) method to add your own fields to the form.
//You may call this method with value null to remove corresponding field from the form.
//You can call this method only after the create() method, when the object is instantiated on the page.
vault.setFormField("customerId", "PS104"); 
vault.setFormField("groupId", null); // will remove this field from the form

Localize text labels

Use vault.strings collection to replace english labels with your localized equivalents.

<script>
vault = new dhtmlXVaultObject();
vault.setImagePath("codebase/imgs/");
vault.setServerHandlers("UploadHandler.php", "GetInfoHandler.php",
		"GetIdHandler.php");
// Translate to German
vault.strings.remove = "Entfernen"; // Remove
vault.strings.done = "Fertig"; // Done
vault.strings.error = "Fehler"; // Error
vault.create("vaultDiv");
</script>

You may replace the following labels:

vault.strings = {
	remove : "Remove",
	done : "Done",
	error : "Error"
};

JSP/Java

To run this sample, copy our “/handlers/jsp” folder to your Tomcat webapp root.
Copy over /codebase folder to the same location.
You can specify upload folder in the “UploadHandler.jsp”, by default it is:
String uploadFolder = “c:\\upload\\”;
Check that this folder has write (or Full) permissions.
We use in this sample Apache’s “commons-fileupload” library extended with our own “ProgressMonitorFileItemFactory”. Those libraries reside on “WEB-INF\lib” and should go to your application’s WEB-INF folder respectively.

除非注明,文章为IT热血青年原创,欢迎转载!转载请注明本文地址,谢谢。
本文地址:http://blog.itblood.com/dhtmlxvault-learning-materials.html

  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.