如何在不刷新页面的情况下自动更新离子列表上的数据

How to auto update data on ionic list without refreshing the page

我创建了一个包含离子列表的页面,如果单击该按钮,它会调用两个按钮,它会调用 firebase api 并得到更新。它更新的,整个列表得到刷新。如何停止刷新整个列表。

 onLocationDataUpdate() {
    // Get current location
    this.geolocation.getCurrentPosition().then(position => {
      this.location.lat = position.coords.latitude;
      this.location.lng = position.coords.longitude;

      // Get location data from Firebase
      this.connectivityServiceService.getLocations(
        this.locatingRange,
        this.location.lat,
        this.location.lng
      );

      // Bind data to Ionic list
      this.dataSetSubscription = this.connectivityServiceService.geoPointLocationUpdateNotify.subscribe(
        locations => {
          const locationData = this.connectivityServiceService.getGeoPointLocations();
          if (locationData.length > this.maxDataCount) {
            const tempLocationData = locationData.slice(0, this.maxDataCount);
            tempLocationData.forEach(item => {
              if (item.feed_back === undefined) {
                item = Object.assign(item, {
                  feed_back: { count: 0, positive: [], negative: [] }
                });
              }
            });
            this.geoPointLocationData = tempLocationData;
            this.loader.dismiss();
          } else {
            const tempLocationData = locationData;
            tempLocationData.forEach(item => {
              if (item.feed_back === undefined) {
                item = Object.assign(item, {
                  feed_back: { count: 0, positive: [], negative: [] }
                });
              }
            });
            this.geoPointLocationData = tempLocationData;
            this.loader.dismiss();
          }
        }
      );
    });
  }

我知道您已经满意地解决了这个问题,但您确实在这里找到了一些东西。

只需将新数据推送到模型,您就会看到它更新,但实际上它正在重新创建整个列表。

如果数据变长,那么这可能会给您带来性能问题。此时你应该查看 trackBy.

这是一种为 Angular 提供跟踪列表中每个单独项目的方法,以便在更新它时,Angular 可以找出哪些实际需要更新,只改变它们。

这好像是 decent introduction to the topic.