arcgis-js-api - 在弹出动作中捕获弹出特征属性
问题描述
我的弹出窗口有一个动作函数,我需要从动作函数中的弹出窗口访问特征属性。在下面的代码中,我想访问 {SAWID}——我在发送给函数的事件参数中看不到它。
var ContactsAction = {
title: "Get Contacts",
id: "contacts-this",
};
var template = {
// autocasts as new PopupTemplate()
title: "{Name}",
content: "{SAWID}",
actions: [ContactsAction]
};
// Event handler that fires each time an action is clicked.
view.popup.on("trigger-action", lang.hitch(this, this.Contacts));
// Executes when GetContacts is clicked in pop ups
Contacts: function (event) {
if (event.action.id === "contacts-this") {
//grab SAWID
}
}
谢谢
皮特
解决方案
我发现了一些可行的方法,尽管它可能不是最好的方法:
even.target 对象上有一个 innerText 属性,其中包括弹出窗口中的所有文本。如果我解析 innerText 属性,我可以得到我需要的东西:如果有人知道更清洁的方法,请告诉我。谢谢
// Executes when GetContacts is clicked in pop ups
Contacts: function (event) {
if (event.action.id === "contacts-this") {
var str = event.target.innerText;
var start = str.indexOf("Close") + 6;//"Close" always precedes my SAWID
var end = str.indexOf("Zoom") - 1;//"Zoom" is always after my SAWID
var SAWID = str.substring(start, end);
alert(SAWID);
}
}
推荐阅读
- unit-testing - Azure DevOps - 为 C# 单元测试运行 VsTest
- php - Laravel API 密钥向后兼容
- python - PyGame 通过附加正方形来制作网格
- string - 如何从文件 csv 将 str 转换为 int
- r - 出错,gcc:“make [4]:gcc:权限被拒绝”(Arch Linux)
- c# - ViewModel 之间的值更新通知
- django - 使用 UML 记录 Django
- r - dump() 用于环境(递归)
- python - 来自不同 DataFrame 列的 Python 绘图线
- javascript - React 如何在没有 npm 的情况下创建通知