2016-06-09 7 views
8

मैं एक GeoJSON फ़ाइल पास करना चाहते हैं JavaScript का उपयोग करके datatable बनाया करने के लिए, मैं फ़ाइल में स्तंभ नाम की पहचान के लिए .. असमर्थ मैं इस की कोशिश की है हूँ का उपयोग कर dyanamically DataTable को GeoJSON सरणी दर्रा कैसे ..जावास्क्रिप्ट

मेरे कोड इस तरह है,

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

और GeoJSON फ़ाइल

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

है

उत्तर

0

समस्या यह हो सकती है कि GeoJSON एक सरणी नहीं बल्कि एक वस्तु है।

इन के साथ अपने स्तंभ परिभाषाओं को बदलने का प्रयास करें:

"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

मैं इस कोशिश की ,, मैं एक त्रुटि, मिल गया "Uncaught TypeError: गुण अपरिभाषित की 'लंबाई' पढ़ा नहीं जा सकता"। – Priyanka

संबंधित मुद्दे