在我的代码中有一个值,我试图将其称为 currentParameter.value,我需要将其设为全局,以便我可以在另一个页面上使用它。出于某种原因,我无法使 currentParameter.value 全局可用。每当我尝试对其发出警报时,我都会不确定。我不知道是什么原因造成的,我认为任何事情都可以全球化。我的代码如下。
function determineTemplate(customInt) {
var templateArray = [];
var hasDropdown = false;
for(var i=0,maxI=customInt.length;i<maxI;i+=1) {
var Interaction = customInt[i];
for(var j=0,maxJ=Interaction.parameterSet.param.length;j<maxJ;j+=1) {
var currentParameter = Interaction.parameterSet.param[j];
if (currentParameter.name === 'INTERACTION-TYPE') {
if (currentParameter.value !== '_itemData') {
var intTemplate = {
'multipleChoice': {"type" : "04719d91", "data" : Interaction, "id" : Interaction.id},
'dragDrop': {"type" : "94ed89c0", "data" : Interaction, "id" : Interaction.id},
'dropdown': {"type" : "8a01a4d0", "data" : Interaction, "id" : Interaction.id},
'select': {"type" : "b1fb3531", "data" : Interaction, "id" : Interaction.id}
};
var currentTemp = intTemplate[currentParameter.value];
if (currentTemplate !== undefined) {
if (currentParameter.value === 'dropdown') {
if (!hasDropdown) {
templateArray.push(currentTemplate);
hasDropdown = true;
}
} else {
templateArray.push(currentTemp);
}
}
}
}
}
};
return templateArray;
};