如何添加数据到动态数组和使用数组在dropbox保护程序api
How to append data to dynamic array and use the array in dropbox saver api?
我创建了几个按钮和按钮url和文件名的onclick发送到动态数组,当我点击dropbox保护程序按钮时,我希望保护程序功能使用该动态数组将文件发送到dropbox。我当前的代码给了我这个错误:丢失的文件。看到文档。
似乎我没有正确地保存数据到数组,我没有正确地传递它到保存函数。有人能帮我解决这个问题吗?由于
注意:我只是想使用我的动态数组,而不是硬编码的url和文件名,如下所示:
编辑:我添加选项。Files = Files;在调用dropbox之前。保存并声明我的数组外addtoarray函数。现在我得到这个错误:G是undefined at dropins.js(第1行)。
files: [
{'url': '<?PHP echo $imagePath1_Value; ?>', 'filename': '1.jpg'},
{'url': '<?PHP echo $imagePath2_Value; ?>', 'filename': '2.jpg'},
{'url': '<?PHP echo $imagePath3_Value; ?>', 'filename': '3.jpg'},
],
Dropbox Api Js:
<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="xxxxxxxxxxxxxx"></script>
<script>
保存fileurl和filename到数组函数:
var i=1;
files = new Array();
function addtoArray(a,b){
alert("URL:"+a+"'nFileName:"+b);
files[i] = { url: +a, filename: +b };
i++;
};
Dropbox saver功能:
function saver(){
var options = {
//here i want to use array i created above instead of hardcode filepath and filenames
//files: [
// You can specify up to 100 files.
// ...
//{'url': '<?PHP echo $imagePath1_Value; ?>', 'filename': '1.jpg'},
//{'url': '<?PHP echo $imagePath2_Value; ?>', 'filename': '2.jpg'},
//{'url': '<?PHP echo $imagePath3_Value; ?>', 'filename': '3.jpg'},
//],
// Success is called once all files have been successfully added to the user's
// Dropbox, although they may not have synced to the user's devices yet.
success: function () {
// Indicate to the user that the files have been saved.
alert("Success! Files saved to your Dropbox.");
},
// Progress is called periodically to update the application on the progress
// of the user's downloads. The value passed to this callback is a float
// between 0 and 1. The progress callback is guaranteed to be called at least
// once with the value 1.
progress: function (progress) {},
// Cancel is called if the user presses the Cancel button or closes the Saver.
cancel: function () {},
// Error is called in the event of an unexpected response from the server
// hosting the files, such as not being able to find a file. This callback is
// also called if there is an error on Dropbox or if the user is over quota.
//error: function (errorMessage) {}
error:function (errorMessage) { alert("ERROR: " + errorMessage); }
};
options.files = files;
Dropbox.save(options);
};
</script>
html正文:
<body>
<button onclick="addtoArray('<?PHP echo $imagePath1_Value; ?>','filename1.jpg')">add to array</button>
<button onclick="addtoArray('<?PHP echo $imagePath2_Value; ?>','filename2.jpg')">add to array</button>
<button onclick="saver()">save</button>
你可以随心所欲地构建你的files
数组,只要options.files
数组在调用Dropbox.save
时包含必要的信息。例如,当你调用addtoArray
时,附加到一个共享的files
变量(现在看起来你每次都在创建一个新的),然后在调用Dropbox.save
之前设置options.files = files
。
相关文章:
- 如何在映射数组中添加换行符
- javascript结合了数组和字典
- 需要帮助设置json数组
- 不能从angular2中的子组件指定父组件中的数组
- 使用JS将数组转换为json对象
- 数组在递归方法中设置为null
- knockoutjs可观察数组
- Javascript-如何读取json文件中的列并将其保存在Javascript数组中
- 将数组从PHP传递到Javascript
- JavaScript数组排序(函数)用于对表行进行排序,而不是排序
- 在函数中添加数组元素的数值
- 无法通过数组映射绑定
- javascript中的数组出错
- 如何使用 node.js 比较两个 json 数组
- Javascript(Angular)从一个对象数组到第二个数组查找值
- 根据id将json数组组合为一个json数组
- 如何通过数组更新角度子范围
- 有没有一种方法可以添加相同的项目val=“0”;4〃;到JavaScript中数组的每个对象
- 在Javascript中转换对象数组
- 如何添加数据到动态数组和使用数组在dropbox保护程序api