在流星方法中使用集合插入中的ID [英] Use id from collection insert within a meteor method

查看:98
本文介绍了在流星方法中使用集合插入中的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Angular/Meteor应用程序中,我想使用客户端中流星方法中的集合插入中创建的ID.

Within my Angular / Meteor app I want to use the created id from a collection insert in a meteor method in the client.

在客户端Angular组件中,存在以下方法.

Within a client Angular component the following method exists.

onSubmit(): void {
  Meteor.call('insertItem', this.item, (error, response) => {
    if (error) {
      ...
    } else {
      this.ngZone.run(() => {
        this.router.navigate(['/item/manage', response]);
      });
    }
  });
} 

此方法调用的流星方法如下所示.

The meteor method that's called by this method looks like following.

insertItem(newItem: Item): Observable<string> {
    return Items.insert(newItem);
}

我想使用插入后返回的ID. 此ID是一个Observable,但在流星方法调用中的响应无法将其识别为Observable.

I want to use the id that's returned after the insert. This id is an Observable, but the response in the meteor method call doesn't recognize it as an Observable.

我可以通过哪种方式将ID返回给客户端并在路由器导航中使用它?

In what way can I return the Id to the client and use it within a router navigate?

推荐答案

我认为错误在于服务器端的流星方法:

I think the error is on the server-side meteor method:

Items.collection.insert(newItem)

添加了.collection后,它将返回新的_id-string.

With the added .collection it will return the new _id-string.

这篇关于在流星方法中使用集合插入中的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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