SitePoint Sponsor

User Tag List

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

    Dynamically creating nodes in a jstree tree structure

    Hi,
    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

    Code:
    	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(jQuery.data(data.rslt.obj[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
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    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

Bookmarks

Posting Permissions

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