当前位置:网站首页>SAP UI5 FileUploader 的隐藏 iframe 设计明细
SAP UI5 FileUploader 的隐藏 iframe 设计明细
2022-07-29 22:49:00 【Jerry Wang】
其实现代码位置如下:
/**
* Helper to retrieve the I18N texts for a button
* @private
*/
FileUploader.prototype.getBrowseText = function() {
// as the text is the same for all FileUploaders, get it only once
if (!FileUploader.prototype._sBrowseText) {
var rb = sap.ui.getCore().getLibraryResourceBundle("sap.ui.unified");
FileUploader.prototype._sBrowseText = rb.getText("FILEUPLOAD_BROWSE");
}
return FileUploader.prototype._sBrowseText ? FileUploader.prototype._sBrowseText : "Browse...";
};从上图可以看出,SAP UI5 框架从一个 library 文件里,根据 key FILEUPLOAD_BROWSE 读取其对应值,结果为 Browse... 这个字符串。
上图 1854 行的三元表达式,代表的逻辑是,如果从 library 文件里根据 key FILEUPLOAD_BROWSE 读取失败,则返回硬编码的默认值 Browse...
SAP UI5 FileUploader 控件所属的 sap.ui.unified 整个库的资源文件位置:https://sapui5.hana.ondemand.com/resources/sap/ui/unified/messagebundle_en_US.properties
关于 SAP UI5 全球化,多语言和翻译的支持,请参阅 Jerry 的教程:SAP UI5 应用开发教程之八 - 多语言的支持
在 FileUploader 的 onAfterRendering 钩子里,执行 prepareFileUploadAndIFrame:
首先为 file upload 做准备:
不要把这个 this.oFileUpload 同之前的 this.oFilePath 相混淆。
这个 aFileUpload 是存储最后渲染出原生 HTML 源代码的场所。
最后生成的源代码:
'<input ', 'type="file" ', 'aria-hidden="true" ', 'name="myFileUpload" ', 'id="__xmlview0--fileUploader-fu" ', 'tabindex="-1" ', 'size="1" ', 'title="Upload your file to the local server" ', '>' this.oFileUpload = jQuery(aFileUpload.join("")).prependTo(this.$().find(".sapUiFupInputMask")).get(0);上面代码通过 jQuery 代码查找的 css 类:sapUiFupInputMask,在 elements 面板里位置如下:
最后 this.oFileUpload 指向 jQuery 通过 css 选择器返回的 dom 实例:
也就是这个 input 字段:
<input type="file" aria-hidden="true" name="myFileUpload" id="__xmlview0--fileUploader-fu" tabindex="-1" size="1" title="Upload your file to the local server">创建隐藏的 iframe,并且插入到 static area 里:
给这个隐藏的 iframe 注册 load 事件:
点击 Browse... 按钮之后,会弹出选择本地文件的对话框:
然后触发 handlechange,使用 var uploadForm = this.getDomRef("fu_form"); 拿到 form 实例:
通过事件对象的 target.files 字段,拿到用户选择好的本地文件。
抛出一个 change 事件:
边栏推荐
猜你喜欢

华为14天-(3)内核开发

Baidu Intelligent Cloud Zhangmiao: Detailed explanation of enterprise-level seven-layer load balancing open source software BFE

Topics in Dynamic Programming

MySQL的TIMESTAMP数据类型

设计消息队列存储消息的MySQL表格
四、HikariCP源码分析之初始化分析一

MySQL Interview Questions: Detailed Explanation of User Amount Recharge Interview Questions

How to realize object selection in canvas (5)

@Accessors 注解详解

分支语句那些事儿(上)~~~~看完少走两月弯路!!
随机推荐
【微信小程序】一文解忧,事件绑定
八、HikariCP源码分析之ConcurrentBag一
【luogu P8354】多边形(容斥)(NTT优化DP)
JVM 上数据处理语言的竞争:Kotlin, Scala 和 SPL
linkedlist的用处之一:通过结构体成员的地址获取结构体变量的地址
超分之RVRT
Implementation and implementation of Any to Any real-time voice change丨RTC Dev Meetup
@Accessors 注解详解
访问公司内网
数据安全建设
MySQL Interview Questions: Detailed Explanation of User Amount Recharge Interview Questions
JZ76 删除链表中重复的结点
JZ6 从尾到头打印链表
九、HikariCP源码分析之ConcurrentBag二
high-level-rest-client 判断索引是否存在
一个print函数,挺会玩啊?
【面试:并发篇33:cas】原子更新器 原子累加器 缓存一致性问题
NetWorker Knowledge Corner|Easy to get an offer [Networker Interview Questions] What is the difference between a Layer 3 switch and a router?
撰写英文文献有哪些技巧?
【面试:并发篇34:Unsafe】