我有以下功能('submitTitle'),按下按钮时会调用该功能。我有两个单选按钮,由'submitTitle'动态生成。当用户选择“否”单选按钮时,它会触发一个匿名函数,该函数还在其中调用另一个名为“getIndexOfObject”的函数。我的问题是,我不断收到以下错误:'未捕获的ReferenceError:未定义getIndexofObject',即使我已经定义了它。我不明白如何解决这个问题。
var titleArray = [];
UploadMyScript.submitTitle = function(id, callback){
console.log('button '+id + ' pressed');
//disable 'append' button.
document.getElementById(id).disabled = true;
var title_;
var titleToAttach = document.getElementById('txtArea_'+id).value;
if(titleToAttach == ''){
console.log('Please enter a title for this pdf');
// un-disable 'append' button
document.getElementById(id).disabled = false;
}else{
/*HANDLE WEBSERVICE CALL HERE FOR EACH TITLE*/
// Replace spaced in title with %20 (pubmed format for spaces)
searchterm_ = encodeURI(titleToAttach);
console.log('searchterm_: '+ searchterm_);
//AJAX CALL
var formdata = new FormData();
formdata.append('titleSearchParam', searchterm_);
// Create XMLHttprequest
var xmlhttp = new XMLHttpRequest;
console.log('pass0000');
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
console.log('greetings form inside onreadystate');
/*RESPONSE TO AJAX CALL HERE*/
var json_obj = JSON.parse(event.target.responseText);
console.log('responseText: '+ event.target.responseText);
var json_obj = JSON.parse(xmlhttp.responseText);
console.log('responseText: '+ xmlhttp.responseText);
if(json_obj == null || json_obj.title == null){
title_ = titleToAttach;
callback(id, title_);
console.log('null, title: ' + title_);
}else{
.......
var radio_no = document.createElement('input');
radio_no.setAttribute('id', 'radio_no_'+id);
radio_no.type = 'radio';
radio_no.name = 'article';
radio_no.value = '0';
radio_no.addEventListener('click', function(){
// Remove this object from the titleArray
var indexOfObject = getIndexofObject(id, titleArray);
titleArray.splice(indexOfObject, 1);
console.log('titleArray below after splice: ');
console.log(titleArray);
});
}
}
}
xmlhttp.open("POST", "upload_myfiles.php");
xmlhttp.send(formdata);
}
}
// Find the Index of a 'title_fileName' object in titleArray
function getIndexOfObject(id, array){
var id_toMatch = UploadMyScript._('paraHeading_'+id).dataset.uniq_id;
for(i=0; i< array.length ; i++){
if(id_toMatch == array[i]['uniq_id']){
return i;
}
}
}
答案 0 :(得分:4)
错误是正确的,未定义。
您正在调用getIndexofObject
,函数名称为getIndexOfObject
。
O
已大写。