view.popup.watch不是一个函数 – 从arcgis 4.26升级到4.27

huangapple go评论98阅读模式
英文:

view.popup.watch is not a function -upgrading from arcgis 4.26 to 4.27

问题

我有一行代码,在ArcGIS JavaScript API 4.26中正常工作。升级到ArcGIS JavaScript API 4.27后,我收到以下错误消息:

view.popup.watch 不是一个函数

以下是出错的代码行:

view.popup.watch("selectedFeature", (graphic) => {

看起来esri已经弃用了这个方法。有没有人知道在4.27上执行此观察的正确替代方法?

英文:

I have a line of code that was working fine in ArcGIS javascript api 4.26. Updating ArcGIS javascript api from 4.26 to 4.27, I am receiving this error:

view.popup.watch is not a function

Here is the failing line:

view.popup.watch("selectedFeature", (graphic) => {

Looks like esri deprecated this. Does anyone know the correct replacement for performing this watch now on 4.27?

答案1

得分: 2

你可以使用reactiveUtilsArcGIS API - reactiveUtils),似乎该库偏爱这种方式。

reactiveUtils.watch(
  () => view.popup.selectedFeature,
  (graphic) => {
    if (graphic) {
      // ...
    }
  }
);
英文:

You can use reactiveUtils (ArcGIS API - reactiveUtils), it seems that the library is favoring this.

reactiveUtils.watch(
  () => view.popup.selectedFeature,
  (graphic) => {
    if (graphic) {
		// ...
    }
  }
);

答案2

得分: 0

也许问题不在于“watch”,而是弹出窗口尚不可用。请查看https://developers.arcgis.com/javascript/latest/4.27/#breaking-changes中的4.27弹出窗口更改。

  • ... 如果在实例化之前尝试访问view.popup属性,可能会出现一些问题。请参阅加载弹出窗口,了解如何更新您的应用程序以利用这些性能改进的详细信息。

要使用reactiveUtils来监视弹出窗口及其视图模型上的属性,而不是使用watch()方法。

// 这将引发一个错误,因为popup尚未创建。 view.popup.watch("selectedFeature", ...)

// 在弹出窗口属性上使用reactiveUtils.watch(),并可选地使用链接。 reactiveUtils.watch(() => view.popup?.selectedFeature, ...);

-- 来自API参考

英文:

Maybe it's not the "watch" that is the the problem, but that the Popup isn't available yet. See the 4.27 popup changes in https://developers.arcgis.com/javascript/latest/4.27/#breaking-changes

  • ... if attempting to access the view.popup property before it is instantiated, some issues may occur. See Loading the Popup for details on how to update your apps to take advantage of these performance improvements.

To use reactiveUtils to watch properties on the popup and its view model instead of the watch() method.

// This will throw an error that watch() is not a method // since the
popup hasn't been created yet. view.popup.watch("selectedFeature", ...)

// Call reactiveUtils.watch() on popup properties with optional
chaining. reactiveUtils.watch(() => view.popup?.selectedFeature, ...);

-- from API Reference

huangapple
  • 本文由 发表于 2023年6月15日 03:58:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76477143.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定