0

我的架构看起来像:

超级.js:

var superSchema = new Schema({
  title: {
    type: String,
    default: '',
    trim: true
  },
  item: [{
    type: Schema.ObjectId,
    ref: 'Item'
  }]
});

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像这样访问我的 list.html 文件中的 ,{{item[0].name}}但它没有返回任何内容,并且 item[0] 返回了 id。

如何访问我的 Angular html 文件中的 item[0].name?

我的superDuperController.js

$scope.find = function() {
    SuperDuper.query(function(superDuper) {
        $scope.superDuper = superDuper;
    });
};
4

1 回答 1

2

在将响应发送到客户端之前,您需要填充您的项目。

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}}在客户端访问。

于 2013-12-31T05:12:19.517 回答