我开发了一个JavaScript倒数计时器; 我还有一个SharePoint列表,用于检索倒计时的分钟数,其列名是Koha
我正在检索Koha并在变量中初始化; 但是,当我尝试运行该应用程序时,倒数计时器显示NaN?
这就是我检索Koha字段的方式:
function Retrieve(){ currentQuizItem = quizList.getItemById(quizID); var quizName; context.load(currentQuizItem); var koha = currentQuizItem.get_fieldValues()["koha"]; //even if I try to convert it to number it does not work koha = parseInt(Koha); alert(koha); // here I can see my value but later when I initialize this var to countdown it says NaN; }这是我的JavaScript倒计时器
function startTimer(duration, display) { var timer = duration, minutes, seconds; setInterval(function () { minutes = parseInt(timer / 60, 10); seconds = parseInt(timer % 60, 10); minutes = minutes < 10 ? "0" + minutes : minutes; seconds = seconds < 10 ? "0" + seconds : seconds; display.textContent = minutes + ":" + seconds; if (--timer < 0) { timer = duration; } }, 1000); } window.onload = function () { var fiveSec = 60 * koha, //If I make this 60 * 20 it works and there are 20 min to countdown display = document.querySelector('#UItimer'); startTimer(fiveSec, display); };现在,当我运行我的应用程序时,如果向我显示NaN:NaN而不是向我显示计时器
请帮帮我
I have developed a JavaScript countdown timer; also I have a SharePoint list that retrieves the minutes for countdown and its column name is Koha
I am retrieving Koha and initializing in a variable; But when I try running the app the countdown timer shows me NaN?
This is how I am retrieving Koha field:
function Retrieve(){ currentQuizItem = quizList.getItemById(quizID); var quizName; context.load(currentQuizItem); var koha = currentQuizItem.get_fieldValues()["koha"]; //even if I try to convert it to number it does not work koha = parseInt(Koha); alert(koha); // here I can see my value but later when I initialize this var to countdown it says NaN; }This is my JavaScript countdown timer
function startTimer(duration, display) { var timer = duration, minutes, seconds; setInterval(function () { minutes = parseInt(timer / 60, 10); seconds = parseInt(timer % 60, 10); minutes = minutes < 10 ? "0" + minutes : minutes; seconds = seconds < 10 ? "0" + seconds : seconds; display.textContent = minutes + ":" + seconds; if (--timer < 0) { timer = duration; } }, 1000); } window.onload = function () { var fiveSec = 60 * koha, //If I make this 60 * 20 it works and there are 20 min to countdown display = document.querySelector('#UItimer'); startTimer(fiveSec, display); };Now when I run my app if shown me NaN:NaN instead of showing me timer
please help me
最满意答案
由于缺少SP.ClientContext.executeQueryAsync method因此很可能会出现此错误。 指定的方法是必需的,它在服务器上提交挂起的查询,没有它的行
var koha = currentQuizItem.get_fieldValues()["koha"];返回undefined 。
以下是获取列表项的一般示例
var ctx = SP.ClientContext.get_current(); var list = ctx.get_web().get_lists().getByTitle(listTitle); var item = list.getItemById(itemId); ctx.load(item); ctx.executeQueryAsync( function(){ var val = item.get_fieldValues()[fieldName]; //... }, function(sender,args){ console.log(args.get_message()); });Most likely you are getting this error since the SP.ClientContext.executeQueryAsync method is missing. The specified method is mandatory, it submits the pending query on the server, without it the line
var koha = currentQuizItem.get_fieldValues()["koha"];returns undefined.
Here is a generic example for getting list item
var ctx = SP.ClientContext.get_current(); var list = ctx.get_web().get_lists().getByTitle(listTitle); var item = list.getItemById(itemId); ctx.load(item); ctx.executeQueryAsync( function(){ var val = item.get_fieldValues()[fieldName]; //... }, function(sender,args){ console.log(args.get_message()); });未捕获的TypeError:NaN JavaScript Sharepoint(Uncaught TypeError: NaN JavaScript Sharepoint)我开发了一个JavaScript倒数计时器; 我还有一个SharePoint列表,用于检索倒计时的分钟数,其列名是Koha
我正在检索Koha并在变量中初始化; 但是,当我尝试运行该应用程序时,倒数计时器显示NaN?
这就是我检索Koha字段的方式:
function Retrieve(){ currentQuizItem = quizList.getItemById(quizID); var quizName; context.load(currentQuizItem); var koha = currentQuizItem.get_fieldValues()["koha"]; //even if I try to convert it to number it does not work koha = parseInt(Koha); alert(koha); // here I can see my value but later when I initialize this var to countdown it says NaN; }这是我的JavaScript倒计时器
function startTimer(duration, display) { var timer = duration, minutes, seconds; setInterval(function () { minutes = parseInt(timer / 60, 10); seconds = parseInt(timer % 60, 10); minutes = minutes < 10 ? "0" + minutes : minutes; seconds = seconds < 10 ? "0" + seconds : seconds; display.textContent = minutes + ":" + seconds; if (--timer < 0) { timer = duration; } }, 1000); } window.onload = function () { var fiveSec = 60 * koha, //If I make this 60 * 20 it works and there are 20 min to countdown display = document.querySelector('#UItimer'); startTimer(fiveSec, display); };现在,当我运行我的应用程序时,如果向我显示NaN:NaN而不是向我显示计时器
请帮帮我
I have developed a JavaScript countdown timer; also I have a SharePoint list that retrieves the minutes for countdown and its column name is Koha
I am retrieving Koha and initializing in a variable; But when I try running the app the countdown timer shows me NaN?
This is how I am retrieving Koha field:
function Retrieve(){ currentQuizItem = quizList.getItemById(quizID); var quizName; context.load(currentQuizItem); var koha = currentQuizItem.get_fieldValues()["koha"]; //even if I try to convert it to number it does not work koha = parseInt(Koha); alert(koha); // here I can see my value but later when I initialize this var to countdown it says NaN; }This is my JavaScript countdown timer
function startTimer(duration, display) { var timer = duration, minutes, seconds; setInterval(function () { minutes = parseInt(timer / 60, 10); seconds = parseInt(timer % 60, 10); minutes = minutes < 10 ? "0" + minutes : minutes; seconds = seconds < 10 ? "0" + seconds : seconds; display.textContent = minutes + ":" + seconds; if (--timer < 0) { timer = duration; } }, 1000); } window.onload = function () { var fiveSec = 60 * koha, //If I make this 60 * 20 it works and there are 20 min to countdown display = document.querySelector('#UItimer'); startTimer(fiveSec, display); };Now when I run my app if shown me NaN:NaN instead of showing me timer
please help me
最满意答案
由于缺少SP.ClientContext.executeQueryAsync method因此很可能会出现此错误。 指定的方法是必需的,它在服务器上提交挂起的查询,没有它的行
var koha = currentQuizItem.get_fieldValues()["koha"];返回undefined 。
以下是获取列表项的一般示例
var ctx = SP.ClientContext.get_current(); var list = ctx.get_web().get_lists().getByTitle(listTitle); var item = list.getItemById(itemId); ctx.load(item); ctx.executeQueryAsync( function(){ var val = item.get_fieldValues()[fieldName]; //... }, function(sender,args){ console.log(args.get_message()); });Most likely you are getting this error since the SP.ClientContext.executeQueryAsync method is missing. The specified method is mandatory, it submits the pending query on the server, without it the line
var koha = currentQuizItem.get_fieldValues()["koha"];returns undefined.
Here is a generic example for getting list item
var ctx = SP.ClientContext.get_current(); var list = ctx.get_web().get_lists().getByTitle(listTitle); var item = list.getItemById(itemId); ctx.load(item); ctx.executeQueryAsync( function(){ var val = item.get_fieldValues()[fieldName]; //... }, function(sender,args){ console.log(args.get_message()); });
发布评论