gpt4 book ai didi

javascript - MarkLogic Qconsole Javascript 代码输出

转载 作者:行者123 更新时间:2023-12-04 08:56:18 24 4
gpt4 key购买 nike

以下代码:

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

To output the result to the MarkLogic Query Console, please serialise and then iterate the parameters:

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;

关于javascript - MarkLogic Qconsole Javascript 代码输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63817868/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com