Hello,
I recently asked a question (and had it answered) here: http://stackoverflow.com/questions/3364937/jquery-load-json
I have a follow-up question, I was hoping to receive some advice on. Basically, I am loading data into the following div: "#my_div"
, which is actually a child element of another div, "#accordion"
, which is an accordion (jQuery UI).
My code looks like this:
$("#accordion").accordion({collapsible: true, clearStyle: true });
function load_list() {
$.getJSON('json/load.php', function(data) {
$("#my_div").empty();
$.each(data, function(k, v){
$("#my_div").append('
<li> \
<div> \
<input type="checkbox"> \
</div> \
<div>'+v.due_date+'</div> \
<h3> \
<span>'+v.title+'</span> \
</h3> \
</li> \
');
});
});
}
And the HTML:
<div id="accordion">
<div id="my_div">JSON elements loaded here.</div>
</div>
However, the problem is: upon the page loading, and then the JSON elements, the accordion does not automatically resize to fit JSON-loaded elements. Only if I collapse the accordion, and then reopen, you can properly see the elements. (This happens in both FF and IE).
I have tried placing $("#accordion").accordion({collapsible: true, clearStyle: true });
at the end of the load_list()
function, but am still getting the same result. Any help on this would be great.
Thanks very much!
UPDATE:
Per the suggestions below, I have tried a few different methods, but am still running into the same issue.
Here is the most recent code I have tried:
function load_tasks() {
$.ajax({
url: 'json/load.php',
dataType: 'json',
success: function(data) {
$.each(data, function(k, v){
$(("#my_div").append('
<li> \
<div> \
<input type="checkbox"> \
</div> \
<div>'+v.due_date+'</div> \
<h3> \
<span>'+v.title+'</span> \
</h3> \
</li> \
');
});
$("#accordion").accordion({collapsible: true, clearStyle: true, autoHeight: true });
}
});
}
I have also tried the other suggestions of autoHeight (which is true by default, no?), as well as the 'resize' method.
None of these appear to be working, unfortunately. If anyone else has any suggestions, they'd be greatly appreciated. Or perhaps, this is just something that cannot be accomplished in this particular situation.