Javascript 当父集合的id不在URL中时,如何获取子集合?
我有一本书和一个章节集。在名为book_list.html的模板中,有一个each语句,列出了所有书籍项目:Javascript 当父集合的id不在URL中时,如何获取子集合?,javascript,meteor,Javascript,Meteor,我有一本书和一个章节集。在名为book_list.html的模板中,有一个each语句,列出了所有书籍项目: 告诉我,你在模板中使用单词助手的位置?在{{{each}}循环中,你可以在模板中用{{u id}或这个来获取当前书籍的id。{u id}在助手中。@ajduke它在book{u item.html中类似于{{title}{{words}}。@user3557327否,即使我使用了这个。文档没有被检索,我想这是因为它没有被订阅。 <!-- book_list.html -->
告诉我,你在模板中使用单词助手的位置?在{{{each}}循环中,你可以在模板中用{{u id}或这个来获取当前书籍的id。{u id}在助手中。@ajduke它在book{u item.html中类似于{{title}{{words}}。@user3557327否,即使我使用了这个。文档没有被检索,我想这是因为它没有被订阅。
<!-- book_list.html -->
<template name="bookList">
<div class="book-list">
{{#each books}}
{{> bookItem}}
{{/each}}
</div>
//publications.js
Meteor.publish("books", function() {
return Books.find({});
});
Meteor.publish("chapters", function(bookId) {
return Chapters.find({
bookId: bookId
}, {
sort: {
position: 1
}
});
});
//route.js
Router.map(function() {
this.route("bookList", {
path: "/",
waitOn: function() {
return Meteor.subscribe("books");
},
data: function() {
return Books.find({});
}
});
});
//book_item.js
Template.bookItem.helpers({
words: function() {
var chapters = Chapters.find({
bookId: this._id
}).fetch();
// code for the word counter