我的JavaScript代码中有以下功能,当我运行它时,显示以下错误Cannot read property 'toString' of undefined
我正在开发一个SharePoint Web应用程序。
function startTest(quizID) {
currentQuizItem = quizList.getItemById(quizID);
var quizName;
context.load(currentQuizItem);
var userName = user.get_title();
var audiencenames = currentQuizItem.get_fieldValues()["Audienca"];
var straudience = audiencenames.toString();
straudience = straudience.toUpperCase();
straudience = straudience.replace(/\s/g, '');
userName = userName.toUpperCase();
userName = userName.replace(/\s/g, '');
var rezultati = straudience.match(userName);
alert(rezultati);
}
请帮助我!
答案 0 :(得分:0)
context.executeQueryAsync()
是我的代码遗失的内容。我添加了它并且它有效。
function startTest(quizID) {
currentQuizItem = quizList.getItemById(quizID);
var quizName;
context.load(currentQuizItem);
var userName = user.get_title();
context.executeQueryAsync(function() {
var audiencenames = currentQuizItem.get_fieldValues()["Audienca"];
var straudience = audiencenames.toString();
straudience = straudience.toUpperCase();
straudience = straudience.replace(/\s/g, '');
userName = userName.toUpperCase();
userName = userName.replace(/\s/g, '');
var rezultati = straudience.match(userName);
alert(rezultati);
},
function() {
// handle error
});
}