problem with treeview plugin and loop

problem with treeview plugin and loop

Hello

I have a problem with class="closed" because it's inside a loop

when i try to use pagination, i am forced to come back on the first page every time

I can't have root folder and sub folder in the same page because of two nested loops

$(document).ready(function() {

$("#browser").treeview({
     persist: "cookie",
     persist: "location",
     collapsed: true});
 $("#add").click(function() {
     var branches = $("<li><span class='folder'>New Sublist</span><ul>" +
         "<li><span class='file'>Item1</span></li>" +
         "<li><span class='file'>Item2</span></li>" +
         "</ul></li>").appendTo("#browser");
     $("#browser").treeview({
         add: branches
     });
 });
});



<ul id="browser" class="filetree ">


{% for category in object_list %}


<li class="closed"><span class="folder"><a href="{{ category.get_absolute_url }}">{{ category }}</a></span>

{% if category.get_materiaux %}
<ul>
{% with category.get_materiaux as mat_list %}
{% autopaginate mat_list 5  %}
 
  {% for mat in mat_list %} 
  <li class="open" ><span class="file"><a href="{{ mat.get_absolute_url }}"> {{ mat }} </a></span></li>    
  {% endfor %}


{% paginate %}
{% endwith %}
</ul>

{% endif %}

</li>


{% endfor %}

</ul>