来自 url 的 objectId 与使用meteorjs 的mongo [英] objectId from url to match with one in the mongo using meteorjs

查看:37
本文介绍了来自 url 的 objectId 与使用meteorjs 的mongo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是流星 js 的新手.我从 url 获得了 id,但我无法将它与 mongodb 中的 id 匹配.可以帮我吗

I am new to meteor js. I got the id from url but i am failing to match it with the id in the mongodb. can any help me

Router.map(function () {
  this.route('post', {
    template:'viewpost',
    path: '/post/:_id',
    data: function () {
     var id = new ObjectID(this.params._id);
      return Tasks.findOne({_id: id});

    }

  });

推荐答案

我怀疑您想返回单个任务?您从 this.params 访问 _id,其中 this 指的是路由器.

I suspect you want to return a single task? You access the _id from this.params where this refers to the router.

Router.map(function () { 
        this.route('post', { 
            template:'viewpost', 
            path: '/post/:_id', 
            data: function () { 
                return Tasks.findOne(this.params._id);
            }
});

在您的模板中,您可以开始引用任务,因为它将是模板的数据上下文;

In your template you can start referring to the task because it will be the data context for the template;

<p>{{description}}</p>

假设您的任务集合中有一个描述字段.

Assuming you have a description field in your Tasks Collection.

这篇关于来自 url 的 objectId 与使用meteorjs 的mongo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆