I'm creating a nested nested nested list, but I'm having problem assigning my buffer inside a UL.
I tried $('ul#lists').html(buffer) but it didn't print out...
JSON
{
"browse": [
{
"name":"browse by state" ,
"command":"state" },
{
"name":"browse by equipment" ,
"command":"equipment" },
{
"name":"browse by brand" ,
"command":"brand" }
]
}
HTML
<section id="browser">
<ul id="lists"></ul>
</section>
JQuery
$(function(tree_click){
$('ul#lists').on('click','.c',function(){
var test = "";
$(this).removeClass('c'); //To assign this event once
$.get('scripts/list.json', function(result, status){
var buffer = "";
$.each(result, function(i, val){
for(var i=0; i < val.length; i++){
var item = val[i];
buffer+="<li><a href='#' cmd='"+item.command+"'>"+item.name+"</a></li>";}
});
$(e.target).parent().append(buffer);
});
});
});
The problem is solved. I updated my question with the solution.
But now my list toggler isn't working.
I use this for the toggler,
$(function(toggle_list){
$("#lists").on('click','a', function() {
return !($(this).parents("li:first").find("ul:first").slideToggle('fast'))
});
});
Any takes?
$.getresults usingconsole.log(result)to see whether your results are returning as you expect?jSONis valid and it returns the result as expected. I evenconsole.log(buffer)and it works as expected. But the problem lies to how should I nest the<li>inside<ul>, like this<ul id=lists><li>result1<ul><li>result1.2</li></ul></li></ul>$('#lists').append(buffer);?appenddid the job! How did I miss that. How do I assign this append only to the button that is clicked? I tried using$(this)but somehow it lies inside the$.getmethod.