0

这应该非常容易......我正在尝试制作一个totalContent包含其他三个变量内容的标记属性,以便更轻松地搜索基于多个过滤器的标记。

当前代码如下所示:

downloadUrl("genxml.php", function(data) {
    var xml = data.responseXML;
    var markers = xml.documentElement.getElementsByTagName("marker");

    for (var i = 0; i < markers.length; i++) {
        var name = markers[i].getAttribute("name");
        var country = markers[i].getAttribute("country");
        var skills = markers[i].getAttribute("skills");
        var interests = markers[i].getAttribute("interests");
        var languages = markers[i].getAttribute("languages");
        var totalContent = skills + " "+interests+" "+languages+ " ";
    //window.alert(totalContent);  --this works, it contains all the content--
        var point = new google.maps.LatLng(
            parseFloat(markers[i].getAttribute("lat")), 
            parseFloat(markers[i].getAttribute("long")));

            var html = "<b>" + name + "</b> <br/>" + country + "<br/><b>Skills:</b>" + skills + "<br/><b>Interests:</b>" + interests + "<br/><b>Languages:</b>" + languages;

            var marker = new google.maps.Marker({
                map: map,
                position: point,
                skills: skills,
                interests: interests,
                languages: languages,
                totalContent: totalContent // is this proper?

        });
        marker.skills = skills;
        marker.interests = interests;
        marker.languages = languages;
        marker.totalContent = totalContent;  //the top three works, but this doesn't?

        gmarkers.push(marker);

    }


});

当我尝试在脚本中的任何其他位置甚至在 Chrome 控制台中调用 gmarkers[i][totalContent] 时,totalContent 显示为未定义。我该如何解决这个问题?

谢谢

4

1 回答 1

0

我得到的数据是 gmarkers[i].totalContent 而不是 gmarkers[i][totalContent]。可能对其他人有帮助。

于 2013-07-18T13:52:00.883 回答