我正在尝试删除两个动词及其相关语句,这段代码可以正常工作,但我发现它效率很低。我尝试将动词放在一个数组中,然后引用每个行中的数组项,其中动词被命名但引发了错误。我可以使用什么代码来通过我构建的动词数组进行循环?谢谢。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Get 2 verbs</title>
<script src="xapiwrapper.min.js"></script>
</head>
<body>
<div id='demo'></div>
<script>
var text = "";
ADL.XAPIWrapper.changeConfig({"endpoint":"https://lrs.adlnet.gov/xapi/"});
var search = ADL.XAPIWrapper.searchParams();
search['verb'] = ADL.verbs.completed.id;
search['since'] = "2017-08-08T08:34:16Z";
var res = ADL.XAPIWrapper.getStatements(search);
if (res) {
text = JSON.stringify(res);
}
var text2 = "";
ADL.XAPIWrapper.changeConfig({"endpoint":"https://lrs.adlnet.gov/xapi/"});
var search = ADL.XAPIWrapper.searchParams();
search['verb'] = ADL.verbs.resumed.id;
search['since'] = "2017-08-08T08:34:16Z";
var res = ADL.XAPIWrapper.getStatements(search);
if (res) {
text2 = JSON.stringify(res);
}
document.getElementById('demo').innerHTML = text + text2;
</script>
</body>
</html>
答案 0 :(得分:0)
也许这样的事情呢?当然未经测试。
var configs = [
{
endpoint: 'https://lrs.adlnet.gov/xapi/',
verb: ADL.verbs.completed.id,
since: "2017-08-08T08:34:16Z"
},
{
endpoint: 'https://lrs.adlnet.gov/xapi/',
verb: ADL.verbs.resumed.id,
since: "2017-08-08T08:34:16Z"
}
];
var out = '';
configs.forEach(function(cfg) {
ADL.XAPIWrapper.changeConfig({"endpoint":cfg.endpoint});
var search = ADL.XAPIWrapper.searchParams();
search['verb'] = cfg.verb;
search['since'] = cfg.since;
var res = ADL.XAPIWrapper.getStatements(search);
if (res) {
out += JSON.stringify(res);
}
});
console.log(out);
答案 1 :(得分:0)
如果您询问是否可以在单个请求中使用任一动词返回语句列表,则标准XAPI搜索不支持该语句。您需要提出多个请求并在最后合并两组语句。