我的架构如下所示:
超级.js:
var superSchema = new Schema({
title: {
type: String,
default: '',
trim: true
},
item: [{
type: Schema.ObjectId,
ref: 'Item'
}]
});
项目.js:
var itemSchema = new Schema({
name: {
type: String,
default: '',
trim: true
}
});
然后我的 json 看起来像这样:
[{
"title": "Team 1",
"items": [
"52c23f2129sdf1720d000006",
"52c23f2129asd1720d000006",
"52c23f212992cfdsd00000f6"]
},{
"title": "Team 2",
"items": [
"52c23f2129sdf1720d000006",
"52c23f2129asd1720d000006",
"52c23f212992cfdsd00000f6"]
}]
然后我尝试访问我的列表中的item[0].name
.html像这样{{item[0].name}}
文件,但它不返回任何内容,item[0] 返回 id。
如何访问我的角度 html 文件中的 item[0].name?
我的超级控制器.js:
$scope.find = function() {
SuperDuper.query(function(superDuper) {
$scope.superDuper = superDuper;
});
};
您需要在将响应发送到客户端之前填充项目。
Super.find({_id: super_id}).populate('item').exec(function(err, super) {
if(err) {
}
else {
// Populated the items
// Send the **super** in response
}
})
现在,您可以在客户端访问{{item[0].name}}
。