0

我在商店中有以下数据:

{
 properties : 
  [
   {
    _id: 123.
    name: "Nice property"
   },
   {
    _id: 456.
    name: "Another nice property"
   }
 ]
}

在我的ngOnInit方法中,我想从商店中选择一个属性来计算一个作为 queryParam 传递的 id,如下所示:

javascript
this.id = this.route.snapshot.paramMap.get('id');
this.property = this.ngRedux.select( state => state.properties).pipe(find( property => property._id === this.id))

显然,这不起作用,但它抓住了我想要做的事情的精神。

使用 ngRedux 通过 id 进行谷歌搜索几乎没有带来什么,所以我怀疑我这样做是错误的。

但是,我尝试使用 解决此问题.subscribe,然后所有逻辑都必须在订阅回调中,这似乎是错误的,并且在我尝试制作反应式表单时不起作用。

4

1 回答 1

0

试试这个:

this.property = this.store.select((state) => state.properties)
    .pipe(map(properties => properties.find(x => x_.id == this.id)));

这应该适用于您给定的场景。您只需从商店中选择属性,然后返回与您的 id 匹配的第一个属性。

于 2019-05-19T16:01:05.287 回答