Angularjs对geojson对象的foreach

angularjs foreach on a geojson object

本文关键字:foreach 对象 geojson Angularjs      更新时间:2023-09-26

我想知道如何在一个geojson对象中使用forEach访问angularjs的特定值

见代码和错误:

my geojson:

var Field = {
    "type": "FeatureCollection",
    "features": [
    {
        "geometry": {
            "type": "Point"     },
        "type": "Feature",
        "properties": {
            "test": "tge",
            "test2": "tge"
        },
        "fiche": {
            "id": "1",
            "date_creation": "2014-04-01 00:00:00",
            "date_modification": "2014-04-01 00:00:00"
        },
        },
    {
        "geometry": {
            "type": "Point"     },
        "type": "Feature",
        "properties": {
            "test": "gztgt",
            "test2": "gztgt"
        },
        "fiche": {
            "id": "2",
            "date_creation": "2014-04-01 00:00:00",
            "date_modification": "2014-04-01 00:00:00"
        },
        },
    ]
};
js代码(在控制器中):
    /* scope alternate view */
    $http({method: 'GET', url: urlDataLocalIntern}).
    success(function(data, status, headers, config) {
        eval(data);
        $scope.alternateViewText = Field.features[];

    }).
    error(function(data, status, headers, config) {
        alert("error ");
    });
html代码:
<ul>
    <li ng-repeat="alternate in alternateViewText">
        <p>{{alternate.properties.test}} - {{alternate.properties.test2}}</p>
    </li>
</ul>

当我这样做的时候,会出现这个错误

错误:[ng:areq] http://errors.angularjs.org/1.3.0-beta.8/ng/areq?p0=MapCtrl&p1=not%20aNaNunction%2C%20got%20undefinedat Error (native)

看起来您的mapcontrol没有定义。你可以发布一个jsfiddle链接或其他与整个片段?

p。不要使用eval(),因为它不安全。使用JSON.parse()代替。