I have variable:
var variableDynamic = 1;
// or
var variableDynamic = 1 + i++;
Is there any way to use that to create dynamic variable names, for example something like this:
var variableName + variableDynamic = {};
// or
var (variableName + variableDynamic) = {};
I know what I wrote above is absurd, but this is to explain the idea. Is it possible?
Ok, what I want to do to create element (upload form) every time user click on add new file group, everything is working fine except that plugin that I use for it need special variable for each upload form to trigger upload button (.uploadStoredFiles();).
This is rough code I did:
$('#addOneMoreFileOrGroup').on('click', function(){
var latestFileUploaderId = parseInt($('.well-large .file-uploader').last().attr('id').split('-')[2]) + 1;
$('.well-large .control-group:last').after('<div class="control-group deal-type-online">
<label class="control-label">File / File Group Title:</label>
<div class="controls">
<input class="span4 file-title" type="text">
<span class="question label label-warning" data-title="File / Group Name:" data-content="Name for your file or group of related files (for example your brand logotype in different file formats)." data-original-title="">?</span>
<div id="file-uploader-' + latestFileUploaderId + '" class="file-uploader"></div>
</div>
</div>');
var HERE_I_NEED_DYNAMIC_VAR = new qq.FileUploader({
element: document.getElementById('file-uploader-' + latestFileUploaderId + ''),
action: 'do-nothing.htm',
autoUpload: false,
debug: true,
uploadButtonText: '<i class="icon icon-plus"></i> Select Files...',
onSubmit: function() {
$('#file-uploader-' + latestFileUploaderId + ' .qq-uploader').after('<button id="file-uploader-trigger-' + latestFileUploaderId + '" class="btn btn-primary"><i class="icon-upload icon-white"></i> Upload now</button>');
$('#file-uploader-trigger-' + latestFileUploaderId + '').on('click', function() {
if($(this).parent().parent().parent().parent().find('.file-title').val() !== '') {
HERE_I_NEED_DYNAMIC_VAR.uploadStoredFiles();
} else {
$(this).parent().parent().parent().addClass('error');
}
});
}
});
});
}
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…