2016-06-09 29 views
8

Chcę przekazać jeden plik GeoJSON dynamicznie tworzone DataTable przy użyciu javascript, jestem w stanie zidentyfikować nazwy kolumn w pliku .. Próbowałem to ..Jak zdać GeoJSON tablicę do DataTable dyanamically przy użyciu javascript

My Kod jest podobny do tego,

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

i GeoJSON plik jest

 { 
     "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

Odpowiedz

0

Problem może polegać na tym, że GeoJSON nie jest tablicą, ale obiektem.

Spróbuj zmienić definicje kolumn z nich:

"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

Próbowałem to ,, Mam błędzie „Uncaught TypeError: nie można odczytać własności«długość»undefined”. – Priyanka