添加履行代码以为订单机器人制作购物车。给我未定义的数量参数
Adding fulfilment code to make a cart for order bot. gives me undefined on quantity parameter
the function below prints the item and in what quantity that has been ordered
function confirmitem(agent){
const item = agent.getContext('item'),
Food = item.parameters.Food,
quantity = item.parameters.quantity;
agent.add('Confirming '+Food+' in a quantity of '+quantity);
}
below is the output context
"outputContexts": [{
"name": "projects/simple-dialog-wtckcj/agent/sessions/1a459958-2249-5973-9561-5418940b0b22/contexts/item",
"lifespanCount": 4,
"parameters": {
"Food": "matooke",
"Food.original": "matooke",
"quantity": {
"number.original": "1",
"number": 1
},
"quantity.original": "1"
}
},
{
"name": "projects/simple-dialog-wtckcj/agent/sessions/1a459958-2249-5973-9561-5418940b0b22/contexts/itemconfirm",
"lifespanCount": 4,
"parameters": {
"quantity": {
"number": 1,
"number.original": "1"
},
"quantity.original": "1",
"Food": "matooke",
"Food.original": "matooke"
}
}
]
the actual output is
'Confirming matooke in a quantity of [object Object]'
问题是 item.parameters.quantity
是一个值为
的对象
{
"number.original": "1",
"number": 1
},
当您尝试打印此对象时,打印对象的正常方法就是使用“[object Object]”,如您所见。
您可能想使用 item.parmeters.quantity.number
之类的内容访问此对象内的 "number" 字段。如果你想访问 "original" 值,这正是用户所说的,你可能需要使用类似 item.parameters["quantity.original"]
的东西。您需要使用这种索引方法,因为 "quantity.original" 包含句点。
the function below prints the item and in what quantity that has been ordered
function confirmitem(agent){
const item = agent.getContext('item'),
Food = item.parameters.Food,
quantity = item.parameters.quantity;
agent.add('Confirming '+Food+' in a quantity of '+quantity);
}
below is the output context
"outputContexts": [{
"name": "projects/simple-dialog-wtckcj/agent/sessions/1a459958-2249-5973-9561-5418940b0b22/contexts/item",
"lifespanCount": 4,
"parameters": {
"Food": "matooke",
"Food.original": "matooke",
"quantity": {
"number.original": "1",
"number": 1
},
"quantity.original": "1"
}
},
{
"name": "projects/simple-dialog-wtckcj/agent/sessions/1a459958-2249-5973-9561-5418940b0b22/contexts/itemconfirm",
"lifespanCount": 4,
"parameters": {
"quantity": {
"number": 1,
"number.original": "1"
},
"quantity.original": "1",
"Food": "matooke",
"Food.original": "matooke"
}
}
]
the actual output is 'Confirming matooke in a quantity of [object Object]'
问题是 item.parameters.quantity
是一个值为
{
"number.original": "1",
"number": 1
},
当您尝试打印此对象时,打印对象的正常方法就是使用“[object Object]”,如您所见。
您可能想使用 item.parmeters.quantity.number
之类的内容访问此对象内的 "number" 字段。如果你想访问 "original" 值,这正是用户所说的,你可能需要使用类似 item.parameters["quantity.original"]
的东西。您需要使用这种索引方法,因为 "quantity.original" 包含句点。