MarkLogic Qconsole Javascript 代码输出
MarkLogic Qconsole Javascript code output
以下代码:
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;
以下代码:
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;