我有两个系列:产品和类别。两者的插入工作正常。我的问题是返回产品列表中的类别名称。它与类别中的 _id 一起列出。我需要它的名字。
这是产品系列:
Products = new Meteor.Collection('products');
/*
* Add query methods like this:
* Products.findPublic = function () {
* return Products.find({is_public: true});
* }
*/
var Schema = {};
Schema.Products = new SimpleSchema({
name: {
type: String,
label: "Nome",
optional: false
},
category: {
type: Schema.Categories,
optional: false
},
"category.$.name": {
type: String
},
subcategory: {
type: Schema.Subcategories,
optional: true
},
"subcategory.$.name": {
type: String
},
description: {
type: String,
label: "Descrição",
optional: true,
max: 150
}
});
Products.attachSchema(Schema.Products);
产品助手列出它们:
Template.Products.helpers({
// Return all products
list: function() {
return Products.find({}, {
sort: {
time: -1
},
fields: {
name: true,
category: true,
subcategory: true
}
}).fetch();
}
});
和产品模板:
<template name="Products">
<fieldset>
<legend>
<p class="pull-left">
Produtos
</p>
<a href="{{pathFor 'ProductsNew'}}" class="btn pull-right btn-success btn-sm">Novo Cadastro</a>
<div class="clearfix"></div>
</legend>
<table class="table">
<thead>
<tr>
<th>Nome</th>
<th>Categoria</th>
<th>Subcategoria</th>
<th></th>
</tr>
</thead>
<tbody>
{{#each list}}
<tr>
<td>{{name}}</td>
<td>{{category}}</td>
<td>{{subcategory}}</td>
<td>
<a href="{{pathFor 'ProductsEdit' _id }}" class="btn btn-xs btn-primary">Editar</a>
</td>
<td>
<button class="destroy btn btn-danger btn-xs">Delete</button>
</td>
</tr>
{{/each}}
</tbody>
</table>
</fieldset>
</template>
我怎样才能做到这一点?
这是我的问题的图像: