首页 > 解决方案 > 在弹出动作中捕获弹出特征属性

问题描述

我的弹出窗口有一个动作函数,我需要从动作函数中的弹出窗口访问特征属性。在下面的代码中,我想访问 {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
            }
        }

谢谢

皮特

标签: arcgis-js-api

解决方案


我发现了一些可行的方法,尽管它可能不是最好的方法:

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);
            }
        }

推荐阅读