尝试使用来自现有对象的 jsonata 创建对象
Trying a create a object using jsonata from existing object
正在尝试使用 jsonata 从现有对象创建对象。当数据和表达式放入 jsonata excerciser 时,会生成正确的结果。但是,当我在 Javascript 程序中 运行 它时,会生成错误。
以下是javascript代码
const data = {
"compCode": "0006",
"compState": "MH",
"recvDocNo": "0075",
"buCode": "AC",
"branchCode": "001",
"recvLines": [
{
"lineNo": 1,
"itemId": "00002",
"qtyAccept": 10,
"unitRate": 100,
"basicVal": 1000,
"taxableAmt": 1000,
}
]
};
let expr = {
"compCode": compCode,
"buCode": buCode,
"lineNo": recvLines.lineNo,
"itemId": recvLines.itemId
};
jsonata(expr).evaluate(data);
我收到错误 - ReferenceError: compCode 未定义
当我将其更改为 data.compCode 和所有其他对象属性时,我收到错误 TypeError: path.charAt is not a function。
谁能告诉我如何让它工作。提前致谢
看起来 jsonata()
需要一个字符串表达式作为参数,这在文档中没有明确说明,但显示在 In Nodejs 部分。
const data = {
"compCode": "0006",
"compState": "MH",
"recvDocNo": "0075",
"buCode": "AC",
"branchCode": "001",
"recvLines": [
{
"lineNo": 1,
"itemId": "00002",
"qtyAccept": 10,
"unitRate": 100,
"basicVal": 1000,
"taxableAmt": 1000,
},
{
"lineNo": 2,
"itemId": "00006",
"qtyAccept": 10,
"unitRate": 100,
"basicVal": 1000,
"taxableAmt": 1000,
}
]
};
let expr = `{
"compCode": compCode,
"buCode": buCode,
"lineNo": recvLines.lineNo,
"itemId": recvLines.itemId
}`;
console.log(jsonata(expr).evaluate(data));
<script src="https://cdn.jsdelivr.net/npm/jsonata@1.8.5/jsonata.min.js"></script>
正在尝试使用 jsonata 从现有对象创建对象。当数据和表达式放入 jsonata excerciser 时,会生成正确的结果。但是,当我在 Javascript 程序中 运行 它时,会生成错误。
以下是javascript代码
const data = {
"compCode": "0006",
"compState": "MH",
"recvDocNo": "0075",
"buCode": "AC",
"branchCode": "001",
"recvLines": [
{
"lineNo": 1,
"itemId": "00002",
"qtyAccept": 10,
"unitRate": 100,
"basicVal": 1000,
"taxableAmt": 1000,
}
]
};
let expr = {
"compCode": compCode,
"buCode": buCode,
"lineNo": recvLines.lineNo,
"itemId": recvLines.itemId
};
jsonata(expr).evaluate(data);
我收到错误 - ReferenceError: compCode 未定义
当我将其更改为 data.compCode 和所有其他对象属性时,我收到错误 TypeError: path.charAt is not a function。 谁能告诉我如何让它工作。提前致谢
看起来 jsonata()
需要一个字符串表达式作为参数,这在文档中没有明确说明,但显示在 In Nodejs 部分。
const data = {
"compCode": "0006",
"compState": "MH",
"recvDocNo": "0075",
"buCode": "AC",
"branchCode": "001",
"recvLines": [
{
"lineNo": 1,
"itemId": "00002",
"qtyAccept": 10,
"unitRate": 100,
"basicVal": 1000,
"taxableAmt": 1000,
},
{
"lineNo": 2,
"itemId": "00006",
"qtyAccept": 10,
"unitRate": 100,
"basicVal": 1000,
"taxableAmt": 1000,
}
]
};
let expr = `{
"compCode": compCode,
"buCode": buCode,
"lineNo": recvLines.lineNo,
"itemId": recvLines.itemId
}`;
console.log(jsonata(expr).evaluate(data));
<script src="https://cdn.jsdelivr.net/npm/jsonata@1.8.5/jsonata.min.js"></script>