如何解决MarkLogic Qconsole Javascript代码输出
以下代码:
function* logGenerator() {
console.log(0);
console.log(1,yield);
console.log(2,yield);
console.log(3,yield);
}
var gen = logGenerator();
// the first call of next executes from the start of the function
// until the first yield statement
gen.next(); // 0
gen.next('pretzel'); // 1 pretzel
gen.next('california'); // 2 california
gen.next('mayonnaise'); // 3 mayonnaise
我已从以下站点的“将参数传递到生成器”部分中获取了此代码。我正在尝试在MarkLogic Qconsole中生成此代码 Javascipt Site
前三个项目的输出是
"done": false
"done": false
"done": false
"done": true
//instead of the expected output
gen.next(); // 0
gen.next('pretzel'); // 1 pretzel
gen.next('california'); // 2 california
gen.next('mayonnaise'); // 3 mayonnaise
有人知道为什么这种行为吗?或者我必须做些其他改变吗?
解决方法
Why
:
您使用的console.log
是JavaScript Web API,它将文本输出到控制台。 MarkLogic console.log
将文本输出到server log file
。如果您检查MarkLogic日志文件{MarkLogic-root-directory}/{port-number}_ErrorLog
,则应该看到:
{timestamp} Info: 0
{timestamp} Info: 1 pretzel
{timestamp} Info: 2 california
{timestamp} Info: 3 mayonnaise
要将结果输出到MarkLogic查询控制台,请序列化然后迭代参数:
function* logGenerator(arr) {
for (var chain of arr) {
yield chain;
}
}
let arrObj = ['0','1 pretzel','2 california','3 mayonnaise']
const result = []
for(const chain of logGenerator(arrObj)) {
result.push(chain);
}
result;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。