我开发了一个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而不是显示计时器
请帮我
由于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());
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句