【问题标题】:Angular2: removeAll() in RethinkDB with Horizon APIAngular2:RethinkDB 中的 removeAll() 与 Horizo​​n API
【发布时间】:2017-07-28 18:24:51
【问题描述】:

我对 Angular2、RethinkDB 和 Horizo​​n API 很陌生,我正在构建一个小型 web 应用程序。在这个应用程序中,我试图删除特定表中的所有对象,因此我使用 Horizo​​n API 中的 fetch() 和 removeAll() 函数。问题是以下错误:

removeAll takes an array as an argument

Horizo​​n API 的文档描述了 fetch() 方法返回一个数组,我正在使用这个数组来 removeAll() 数据。 来源: https://horizon.io/api/collection/#fetch

this.table.removeAll(this.table.fetch().subscribe(
  result => console.log('Result:', result),
  err => console.error(err),
  () => console.log('Results fetched')
));

当我记录这个获取的结果时,它显示了一个对象数组。

Result: [Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]

我尝试过早先声明一个数组和许多其他事情,但似乎没有任何效果。有什么想法吗?

【问题讨论】:

    标签: angular typescript rethinkdb removeall horizon


    【解决方案1】:

    您非常接近,但您以错误的方式调用 removeAll。一个例子是这样的:

    ClearTable(): void {
        this.table.fetch().subscribe(
          (returnObjects: Object[]) => {
            this.table.removeAll(returnObjects);
          }
        );
    }
    

    您只能在订阅对象时对其进行操作。将它们传递给一个数组,现在您就可以将正确的对象传递给 removeAll 函数了

    【讨论】:

      猜你喜欢
      • 2016-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多