2016-06-09 3 views
8

ich Datatable will eine GeoJSON-Datei übergeben, um dynamisch erstellt Datentabelle mit Hilfe von Javascript, ich bin nicht in der Lage Spaltennamen in der Datei zu identifizieren .. ich diese ..Wie GeoJSON Array Pass dyanamically mit Hilfe von Javascript

versucht habe

My Code ist wie diese,

<body> 
<table id="example" class="display" cellspacing="0" width="100%"> 
    <thead> 
     <tr> 

      <th>fC.type</th> 
      <th>f.type</th> 
      <th>f.prop</th> 
      <th>f.geom.type</th> 
      <th>geometry.coordinates.0</th> 
      <th>geometry.coordinates.1</th> 

     </tr> 
    </thead> 

</table> 
</body> 



$(document).ready(function() { 
$('#example').dataTable({ 

    "ajax":"data/json_file.json", 
    "processing":true, 
    "columns": [ 

     { "mData": "type" }, 
     { "mData": "features.type" }, 
     { "mData": "features.properties" }, 
     { "mData": "geometry.type" }, 
     { "mData": "geometry.coordinates.0" }, 
     { "mData": "geometry.coordinates.1" } 
    ] 
}); 
}); 

und GeoJSON Datei ist

 { 
     "type": "FeatureCollection", 
     "features": [ 
     { 
      "type": "Feature", 
      "properties": {}, 
      "geometry": { 
      "type": "LineString", 
      "coordinates": [ 
       [ 
       40.078125, 
       57.136239319177434 
       ], 
       [ 
       91.7578125, 
       58.99531118795094 
       ] 
          ] 
         } 
     } 
    ] 
} 

My output is as shown in image

Antwort

0

Das Problem könnte sein, dass GeoJSON kein Array, sondern ein Objekt ist.

Versuchen Sie Spaltendefinitionen mit diesen Wechsel:

diese
"columns": [ 
    { "data": "type" }, 
    { "data": "features.0.type" }, 
    { "data": "features.0.properties" }, 
    { "data": "features.0.geometry.type" }, 
    { "data": "features.0.geometry.coordinates.0" }, 
    { "data": "features.0.geometry.coordinates.1" } 
] 
+0

Ich habe versucht ,, Ich habe einen Fehler „Nicht abgefangene Typeerror: kann Eigenschaft‚Länge‘undefinierter lesen“. – Priyanka

Verwandte Themen