我是机器人框架的新手,并且使用节点 SDK 开发 Skype 聊天机器人。
我有 JSON 树数组,它为我提供树数据的 ID 和名称。
treeName = tree.parse({
"id": 1,
"title": "menu",
"children": [
{
"id": 11,
"title": "company _ data",
"children": [{"id": 111}]
},
{
"id": 12,
"title": "adhoc data test ",
"children": [{"id": 121}, {"id": 122}]
},
{
"id": 13,
"title": "quit",
"children": [{"id": 131}, {"id": 132}]
}
]
});
从树中获取标题的代码。
var node1 = treeName.first(function (node) {
return node.model.id === 1;
});
大批
var firstChild = [];
for (var i = 0; i < node1.model.children.length; i++) {
firstChild.push(node1.model.children[i].title);
}
builder.Prompts.choice(session, "What scenario would you like to run? ",firstChild );
当我尝试获取 id 时,它会很好地工作,但是如果我想在一个数组中获取标题,那么我会收到此错误:
/node_modules/promise/lib/done.js:10
throw err;
^
TypeError: choice.trim is not a function