Display data with JSON string.

Display data with JSON string.

abhinavp18abhinavp18 Posts: 1Questions: 1Answers: 0
edited July 2015 in Free community support

I have a function which has a parameter of JSON string. I am not able to show data in table using that string.

items = "{"items":[{"featureId":"16","name":"weqrds","featureDescription":"","version":"","deployed":false,"enabled":true},{"featureId":"15","name":"weq","featureDescription":"","version":"","deployed":false,"enabled":true},{"featureId":"14","name":"wqer","featureDescription":"","deployed":false,"enabled":true},{"featureId":"13","name":"s","featureDescription":"","deployed":false,"enabled":true},{"featureId":"12","name":"we ","featureDescription":"","deployed":true,"enabled":true},{"featureId":"11","name":"f65 ","featureDescription":"","deployed":true,"enabled":true},{"featureId":"10","name":"ff5 ","featureDescription":"","deployed":true},{"featureId":"9","name":"f4 ","featureDescription":"","deployed":true,"enabled":true},{"featureId":"8","name":"F3 ","featureDescription":"","deployed":true,"enabled":true},{"featureId":"7","name":"F2 ","featureDescription":"","deployed":false,"enabled":true},{"featureId":"6","name":"F1 ","featureDescription":"","deployed":false},{"featureId":"5","name":"Memo ","featureDescription":"","deployed":true,"enabled":true},{"featureId":"4","name":"3D ","featureDescription":"","deployed":true,"enabled":true},{"featureId":"3","name":"Reports ","featureDescription":"","deployed":true,"enabled":true},{"featureId":"2","name":"Save","featureDescription":"","deployed":true,"enabled":true}]}"

function createTable(items){
$('#example').dataTable( {
      "scrollY":"200px",
       "scrollCollapse": true,
       "paging":true,
           "columns": [
                    { "data": "name" },
                    { "data": "featureDescription" },
                    { "data": "featureId" },
                    { "data": "version" },
                    { "data": "deployed" }
                 
                            ]
                    } );
                  }

Answers

  • allanallan Posts: 63,772Questions: 1Answers: 10,511 Site admin

    I don't see where you are actually using items, however it is a string, so you need to confirm it to be "JSON". Use JSON.parse() to do so - MDN documentation.

    Allan

This discussion has been closed.