我有变量:
var variableDynamic = 1;
// or
var variableDynamic = 1 + i++;
有没有办法使用它来创建动态变量名,例如这样的:
var variableName + variableDynamic = {};
// or
var (variableName + variableDynamic) = {};
我知道我上面写的很荒谬,但这是为了解释这个想法。可能吗?
好的,每次用户单击添加新文件组时,我想要创建元素(上传表单),一切正常,除了我使用的插件需要每个上传表单的特殊变量来触发上传按钮(.uploadStoredFiles ();)。
这是我做的粗略代码:
$('#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');
}
});
}
});
});
}