javascript - Uncaught TypeError: Cannot set property 'nodeId' of undefined -
i'm getting error on boostrap-treeview.js:267 when retrieving json data boostrap-treeview.
$(document).ready(function() { $.ajax({ url: "js/category_data.php", method:"post", datatype: "json", success: function(data) { $('#doctypestree').treeview({ data: data }); } }); });
the json data following:
{ "2":{ "id":"12", "text":"certified copy", "description":"","root":"0" }, "3":{ "id":"13", "text":"charter", "description":"", "root":"0" }, "4":{ "id":"14", "text":"codicil (will)", "description":"", "root":"0" }, "5":{ "id":"15", "text":"cohabitation agreement", "description":"", "root":"0" }, "6":{ "id":"16", "text":"collateral assurance", "description":"", "root":"0" }, "7":{ "id":"17", "text":"commercial invoice", "description":"", "root":"0" }, "8":{ "id":"18", "text":"complaint", "description":"", "root":"0" }, "9":{ "id":"19", "text":"conservation easement", "description":"", "root":"0" }, "10":{ "id":"20", "text":"consignee", "description":"", "root":"0" }, "11":{ "id":"21", "text":"consumer complaint", "description":"", "root":"0" }, "12":{ "id":"22", "text":"contract", "description":"", "root":"0" }, "13":{ "id":"23", "text":"contractual term", "description":"", "root":"0" }, "14":{ "id":"24", "text":"contractual terms in english law", "description":"", "root":"0" }, "15":{ "id":"25", "text":"florence annie conybeare", "description":"", "root":"0" }, "16":{ "id":"26", "text":"copyright transfer agreement", "description":"", "root":"0" }, "17":{ "id":"27", "text":"countersign (legal)", "description":"", "root":"0" }, "18":{ "id":"28", "text":"county court judgment", "description":"", "root":"0" }, "19":{ "id":"29", "text":"credit support annex", "description":"", "root":"0" }, "20":{ "id":"30", "text":"customs declaration", "description":"", "root":"0" }, "21":{ "id":"31", "text":"bills", "description":"", "root":"0", "nodes":[ { "id":"4", "text":"bill of costs", "description":"this type gather documents related costs","root":"31" }, { "id":"5", "text":"bill of sale", "description":"","root":"31" } ] } }
i using bootstrap tree view
any ideas
your json object. you'll have convert array tree work. can either change php return proper array or use javascript convert array shown below.
var data = { "2": { "id": "12", "text": "certified copy", "description": "", "root": "0" }, "3": { "id": "13", "text": "charter", "description": "", "root": "0" }, "4": { "id": "14", "text": "codicil (will)", "description": "", "root": "0" }, "5": { "id": "15", "text": "cohabitation agreement", "description": "", "root": "0" }, "6": { "id": "16", "text": "collateral assurance", "description": "", "root": "0" }, "7": { "id": "17", "text": "commercial invoice", "description": "", "root": "0" }, "8": { "id": "18", "text": "complaint", "description": "", "root": "0" }, "9": { "id": "19", "text": "conservation easement", "description": "", "root": "0" }, "10": { "id": "20", "text": "consignee", "description": "", "root": "0" }, "11": { "id": "21", "text": "consumer complaint", "description": "", "root": "0" }, "12": { "id": "22", "text": "contract", "description": "", "root": "0" }, "13": { "id": "23", "text": "contractual term", "description": "", "root": "0" }, "14": { "id": "24", "text": "contractual terms in english law", "description": "", "root": "0" }, "15": { "id": "25", "text": "florence annie conybeare", "description": "", "root": "0" }, "16": { "id": "26", "text": "copyright transfer agreement", "description": "", "root": "0" }, "17": { "id": "27", "text": "countersign (legal)", "description": "", "root": "0" }, "18": { "id": "28", "text": "county court judgment", "description": "", "root": "0" }, "19": { "id": "29", "text": "credit support annex", "description": "", "root": "0" }, "20": { "id": "30", "text": "customs declaration", "description": "", "root": "0" }, "21": { "id": "31", "text": "bills", "description": "", "root": "0", "nodes": [{ "id": "4", "text": "bill of costs", "description": "this type gather documents related costs", "root": "31" }, { "id": "5", "text": "bill of sale", "description": "", "root": "31" }] } }; var dataarray = []; (var key in data) { if (data.hasownproperty(key)) { dataarray.push(data[key]); } }; $('#tree').treeview({data: dataarray});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://rawgit.com/jonmiles/bootstrap-treeview/master/dist/bootstrap-treeview.min.js"></script> <div id="tree"></div>
Comments
Post a Comment