我想通过在 CollectionBrowse 中使用 for 循环来动态显示项目。我正在使用下面的代码,但是当我使用它时,谷歌上的操作会返回错误。
const {
conversation,
Simple,
Card,
Image,
Button,
List,
Link,
Table,
CollectionBrowse,
Suggestion,
Schema
} = require('@assistant/conversation');
const functions = require('firebase-functions');
const app = conversation({debug:true});
app.handle('callApi', (conv) => {
conv.add(new CollectionBrowse({
items:[
{
title: 'Item #1',
description: 'Description of Item #1',
footer: 'Footer of Item #1',
image: {
url: 'https://developers.google.com/assistant/assistant_96.png',
},
openUriAction: {
url: 'https://www.example.com',
},
},
{
title: 'Item #2',
description: 'Description of Item #2',
footer: 'Footer of Item #2',
image: {
url: 'https://developers.google.com/assistant/assistant_96.png',
},
openUriAction: {
url: 'https://www.example.com',
},
},
{
title: 'Item #3',
description: 'Description of Item #3',
footer: 'Footer of Item #3',
image: {
url: 'https://developers.google.com/assistant/assistant_96.png',
},
openUriAction: {
url: 'https://www.example.com',
},
}
]
}));
});
exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app);
我想将我的代码更改为以下示例中的内容。
conv.add(new CollectionBrowse({
items:[
for(var i = 1; i < 4; i++){ <------------------------- i want it!!!!!!
{
title: 'Item #'+i,
description: 'Description of Item #'+i,
footer: 'Footer of Item #'+i,
image: {
url: 'https://www.example.com',
},
openUriAction: {
url: 'https://www.example.com',
},
}
}
]
}));
对于for循环语句我该怎么办,如果不是这样,还有其他方法吗?
谢谢你。