I got some help from my boss on this one. Had to use the empty method $( '#accordion').empty();
to empty out the contents of the accordion div just before my while loop. Also there really is no need for $('#accordion').accordion("refresh");
in my code.
How can I re-create an accordion from a filtered list
-
07-07-2023 - |
Вопрос
I have an accordion which I populate using a custom list. However I have a button which kicks off a javascript function to filter the list based on values in 3 different drop-downs. This also works but my issue is on how to destroy the accordion already on the page and re-create accordion with the new filtered list. At the moment the new list is appended to the old accordion (which at least proves my filter function is working). I have tried using "$('#accordion').append('destroy')" but the new list continues to be appended to the end of the old list.
Here is how I am generating the accordion currently:
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo += '\nRoom Name: ' + oListItem.get_item('Title')+ ' ' +'Building: ' + oListItem.get_item('Building') + ' ' + 'Floor: ' + oListItem.get_item('Floor') + ' ' + 'Seating: ' + oListItem.get_item('Seating')
+ ' ' + 'Phone Number: ' + oListItem.get_item('Phone_x0020_Number') + ' ' + 'Book Room: ' + oListItem.get_item('Book_x0020_Room') ;
var newDiv = "<h3> " +oListItem.get_item('Title').toString() +" </h3><div> <p> Building : " +oListItem.get_item('Building').toString()+" </p> </br><p> Floor :" +oListItem.get_item('Floor').toString()+" </p></br><p> Phone Number :" +oListItem.get_item('Phone_x0020_Number').toString()+" </p></br><p> General Size :" +oListItem.get_item('General_x0020_Size').toString()+" </p></br><p> Book Room : <a href =" +oListItem.get_item('Book_x0020_Room').get_url()+">" +oListItem.get_item('Book_x0020_Room').get_description()+"</a> </p></div>";
$('#accordion').append(newDiv)
$('#accordion').accordion("refresh");
}
I also have this div in my html body:
<div id="accordion"></div>
Решение
Не связан с StackOverflow