SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2011
    0 Post(s)
    0 Thread(s)

    Dynamically creating nodes in a jstree tree structure

    I have to retrieve a list of menu item from a database and display it in a tree structure.I want to use the menu name as the node name and menu id as the id of the node.I'm using php and jstree javascript library
    This is what i wrote but it doesn't give any output.this is what i hv done so far

    	function createNodeList(){
    		$('#menuCPanel #contentData #tree').jstree({			
    			"json_data" : {
    				"ajax" :{
    					"type" : "POST",
    					"url" : "?m=admin",
    					"dataType" : "json",
    					"data" : {
    						"action" : "getNodeList",
    					"success" : function(result){
    							return {							
    								id : result.attr ? result.attr("id") : result['menuId'],
    								title : result.attr ? result.attr("title") : result['menuName']
    				"error" : function(XMLHttpRequest, textStatus, errorThrown) { 
    					alert("err: "+errorThrown);
    			"callback" : {
    			"themes" : {
    				"theme" : "classic",
    		        "dots" : true,
    		        "icons" : true
    			"plugins" : ["json_data", "themes"]
    		}).bind("select_node.jstree", function (e, data) { alert([0], "jstree").id) });
    I would like to know what is wrong with the code.In fact the code returns the desired json data.this is the returned json data
    "data":[{"menuId":"1","menuName":"Top Menu"},{"menuId":"2","menuName":"Main Menu"},{"menuId":"3","menuName":"Bottom Menu"},{"menuId":"4","menuName":"Main Menu"}]
    It would be a greate help if someone can help me
    thanks in advance

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Christchurch, New Zealand
    104 Post(s)
    4 Thread(s)
    There are several trailing-comma issues there. Does correcting those resolve the problem?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts