【发布时间】:2016-12-21 12:54:31
【问题描述】:
我正在使用 Ionic2 / Angular2 和 typescript,但我在过滤数组时遇到了问题。
我有
let localTours = [];
...
let newTours = dbTours.filter(x => localTours.indexOf(x) < 0);
localTours.push(newTours);
在此示例中,我的 localTours 始终为空,因为在过滤之前调用了 .push。知道如何解决这个问题吗?
【问题讨论】:
-
过滤器不是问题,
something()可能是。请显示该功能。您显示的代码中没有任何内容是异步的 -
实际上代码是这样的:
let newTours = dbTours.filter(x => localTours.indexOf(x) < 0);,然后是localTours.push(newTours);。我将更新问题中的代码。 -
更新您的代码以包含
localTours的来源。 -
dbTours 怎么样?那是一个数组,还是一个 db 对象?类似于 ORM 的东西?而filter方法其实是在逆db?
-
这是我订阅
Observable<Tour[]>的数组。
标签: javascript angular asynchronous typescript array-filter