繁体   English   中英

meteor.js-在哪里调用集合的查找

[英]meteor.js - where to call a lookup to a collection

因此,我有两个集合,即“帖子”和“位置”,以及一个简单的html表单,供用户将自己添加到帖子集合中。 添加后,我将显示所有用户的列表,但是如果他们具有在“位置”集合中显示的属性,还希望向此列表添加一些额外的数据。

因此,例如,用户表单具有“名称”,“年龄”,“位置”,并且“位置”集合具有有关他们所居住位置的信息,例如“英国伦敦,首都”。 如果来自伦敦的用户输入了他们的详细信息,则我希望在“位置”集合中显示他们在表单上输入的详细信息以及“您住在首都”的信息。

因此,一些代码可以从表单中插入详细信息:

post_submit.js:

Template.postSubmit.events({
  'submit form': function(e) {
    e.preventDefault();

    var post = {
      name: $(e.target).find('[id=usersName]').val().toUpperCase();,
      age: $(e.target).find('[id=age]').val(),
      location: $(e.target).find('[id=location]').val().toUpperCase(),
    };

    Meteor.call('postInsert', post, function(error, result) {
      // display the error to the user and abort
      if (error)
        return throwError(error.reason);

      Router.go('postPage', {_id: result._id});  
    });
  }
});

并在posts.js中

Meteor.methods({
  postInsert: function(postAttributes) {

    var post = _.extend(postAttributes, { 
      submitted: new Date(),
    });

    var postId = Posts.insert(post);

    return {
      _id: postId
    };
  }
});

但是,我如何定义对Locations集合的预订以及在何处调用该集合的“查找”以查找位置,然后使我能够在页面的其他部分中显示该位置。 我敢肯定这很简单,但是我在努力连接各个点。

您必须创建一个新的出版物,该出版物将发布帖子,然后将位置作为“依赖项”发布。 有一个软件包可以使这一过程变得非常简单。 copleykj:simple-publish将帮助您完成此任务。 自述文件中的示例应足以使您入门。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM