javascript - JqueryMobile Getting details about Item Clicked -
i have 3 level hierarchy.the first 2 levels collapsible whereas final 1 list.when click list have pass data list item clicked , name of parent , grand parent. unable data item clicked .the js code (read below code also)
var commodity; var variety; var grade; var content; var jsons ='[{"turmeric":[{"bulb":["grade 2","grade 1"]},{"finger":["grade 1"]}]}]'; var data = $.parsejson(jsons); var nextid = 0; $.each(data, function(key, value){ $.each(value, function(key, value){ //runs each commodity commodity = key; var data1 = value; $(document).on("pageinit", function() { nextid++; content = "<div data-role='collapsible' data-collapsed-icon='arrow-r' , data-expanded-icon='arrow-d' id='setk'><h3> " + commodity + "</h3><p>"; $.each(data1, function(key, value){ $.each(value, function(key, value){ variety = key; content = content + "<div data-role='collapsible' data-collapsed- icon='arrow-r' , data-expanded-icon='arrow-d' id='setk'><h3> " + variety + "</h3> <p>"+ '<ul data-role="listview" id="noth">'; for(var i=0, len=value.length; < len; i++){ grade = value[i]; invis = commodity+variety+grade; content=content+'<li><a href="ext.html" id=commodity onclick=senddata(?????) rel="external">'+grade+'</a></li>'; } content = content + '</ul>'; content = content + "</p></div>"; }); }); content = content +"</p></div>"; $("#set").append( content ).collapsibleset('refresh'); $("#set").enhancewithin(); }); }); }); function senddata(data) { localstorage["1"] = data; alert(data); }
please not:if give parameter of grade or variety or commodity onclick method ,it sends last updated value of these not correct
a few points along:
first, re-using variables need not touch:
$.each(data, function(key, value){ $.each(value, function(key, value){
the inner $.each() replaces whatever values have in key , value.
second, not need bind pageinit event in loop; fire multiple times. pageinit deprecated.
Comments
Post a Comment