2016-06-09 24 views
8

Tôi muốn vượt qua một file GeoJSON để tự động tạo ra DataTable sử dụng javascript, tôi không thể xác định tên cột trong tập tin .. Tôi đã thử này ..thế nào để Pass mảng GeoJSON để DataTable dyanamically sử dụng javascript

My code đang như thế này,

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

và tập tin GeoJSON là

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

Trả lời

0

Vấn đề có thể là GeoJSON không phải là một mảng mà là một đối tượng.

Hãy thử thay đổi định nghĩa cột của bạn với những:

"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

Tôi cố gắng này ,, tôi đã nhận ra lỗi, "Loại lỗi chưa gặp: Không thể đọc thuộc 'chiều dài' không xác định". – Priyanka

Các vấn đề liên quan