update a VAR in javascript
How can I update the "storage" var set in uploadify? I have this function set_path
that updates the var combined to other values that is launched when some content is selected
$(document).ready(function () {
$('#uploader').u开发者_如何学JAVAploadify({
'uploader': '/admin/includes/uploadify/uploadify.swf',
'script': '/admin/includes/uploadify/uploadify_storage.php',
'scriptData': {
'sessionId': sessionId
},
'cancelImg': '/admin/includes/uploadify/cancel.png',
'buttonImg': '/site_images/button.png',
'folder': storage,
'auto': false,
'multi': true,
'fileExt': '*.jpg',
'simUploadLimit': 2,
'wmode': 'transparent',
'onComplete': function (event, ID, fileObj, name, response, data) {
alert(storage);
}
});
$("#start").click(function () {
$("#uploader").uploadifyUpload();
});
})
var absolute_path = "/admin/storage/files/";
var path = "";
var storage = absolute_path + path;
function set_path(new_path) {
storage = absolute_path + new_path;
show_path(new_path);
}
if set_path is launched the new storage var is updated infact the alert in "onComplete" shows the right content, the problem is that 'folder': storage
contains the original "storage", and is not getting updated when setting a new path. Why?
Because the storage variable was only used to pass the value to uploadify settings array upon instantiating, it doesn't "live" there.
What you want to do is alter the 'folder' setting for the uploadify object.
According to Uploadify documentation, your set_path function should look like this:
function set_path(new_path) {
$('#uploader').uploadifySettings ('folder', absolute_path + new_path);
show_path(new_path);
}
Since you fed the original object to the folder
property, you need to re-set the value of the key.
In onComplete
, grab a reference to the object you fed, or create a setter method and set its folder property to the new storage.
精彩评论