【发布时间】:2014-08-10 07:10:34
【问题描述】:
我在使用 Node 和 Angular 从 JSON(来自 MongoHQ 的 BSON)读取嵌套数组时遇到问题。
JSON sn-p:http://pastie.org/9305682。专门寻找边缘数组。
猫鼬模型:http://pastie.org/9305685
基本上我从数据库调用字符,然后尝试将其记录到控制台 console.log(char); 在将其发送回带有 res.json(char); 的角度调用之前,'char' 是从数据库中返回的字符,保存为我的猫鼬模型。
正在尝试将角色记录到控制台。 除了嵌套“效果”数组的部分之外,我得到的一切看起来都很正常。无论他们出现在哪里,我都会收到以下信息:
edges:
[ { name: 'Super Hacker', notes: '', effects: [Object] },
{ name: 'Witty', notes: '', effects: [Object] },
{ name: 'Attractive', notes: '', effects: [Object] },
{ name: 'Encyclopedic Memory',
notes: 'Prereq: d8 Smarts',
effects: [Object] },
{ name: 'Daywalker', notes: '', effects: [Object] },
{ name: 'Tough', notes: '', effects: [Object] } ],
如果我尝试用以下方式调用它,请从这里开始:
来自 NodeJS - console.log(char[0].edges[0].effects[0].type); - 返回未定义。
从角度视图 - {{cur_char.edges[0].effects[0].type}} - 什么都不显示。
提前感谢您的帮助。如果我能提供更多信息,请告诉我。
【问题讨论】:
-
您是否尝试过仅使用 console.log(char[0].edges[0].effects[0]) 来查看对象是否以 JSON 格式返回?
-
调用这个我得到 [object Object]。
标签: javascript json node.js angularjs mongodb