Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当父集合的id不在URL中时,如何获取子集合?_Javascript_Meteor - Fatal编程技术网

Javascript 当父集合的id不在URL中时,如何获取子集合?

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 -->

我有一本书和一个章节集。在名为book_list.html的模板中,有一个each语句,列出了所有书籍项目:


告诉我,你在模板中使用单词助手的位置?在{{{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