Sencha Touch 不支持输入类型文件,所以我尝试使用一些 html 来执行此操作
config: {
html: '<input type="file" onchange="readURL(this);">',
但我只能在我的应用程序之外调用函数..
有人知道我如何调用控制器功能吗?
Sencha Touch 不支持输入类型文件,所以我尝试使用一些 html 来执行此操作
config: {
html: '<input type="file" onchange="readURL(this);">',
但我只能在我的应用程序之外调用函数..
有人知道我如何调用控制器功能吗?
它不是很漂亮,但在 Sencha Touch 框架中实现此功能之前,它是一种解决方法。这是我在视图文件中使用的代码
config: {
html: '<input type="file" onchange="readURL(this);">',
一旦选择了文件,就会调用函数 readURL。从这个函数中,我使用以下代码调用我的应用程序\控制器\函数\
function readURL(input) {
window['myAppName'].app.getController('myControllerName').photoToStore(photo);
}
在 photoToStore 函数中,我得到了照片的 base64
photoToStore: function(photo) {
var reader = new FileReader();
var img = new Image();
reader.readAsDataURL(photo.files[0]);
reader.onload = function(e) {
img.src = e.target.result;
}
}
在最后一步中,我将 base64 刺痛发送到后端,我可以将照片保存为文件。