JQuery mobile cannot update collapsibleset

I am creating an application using jQuery mobile and loading its menu and pages from wordpress throw jsonp. I loding his menu in the form of collapsibleset and listview, but I keep getting errors. when i try to update collapsibleset with this code

$(".childnev").html(list); $.mobile.loading( 'hide'); $('.popupmenu').slideToggle('slow'); $(".childnev").collapsibleset('refresh'); $(".childsublist").listview().listview('refresh'); 

It gives me this error

 Error: cannot call methods on collapsibleset prior to initialization; attempted to call method 'refresh' 

And when I try to update this code.

 $(".childnev").html(list); $.mobile.loading( 'hide'); $('.popupmenu').slideToggle('slow'); $(".childnev").collapsibleset(); $(".childnev").collapsibleset('refresh'); $(".childsublist").listview().listview('refresh'); 

He gives me this error again

 TypeError: o[0] is undefined 

Am I missing something or did something wrong?

+4
source share
4 answers

All you have to do is add this

Demo

 $('[data-role=collapsible-set]').collapsibleset().trigger('create'); 

This will increase the markup of [data-role=listview] and [data-role=collapsible-set] for the current page (active page). You can replace $('[data-role=collapsible-set]') with any selector.


Note (s)

  • Based on the script in comment , you have many errors. .ready should not be used with jQuery Mobile. Also, .live no longer in use, so replace .live with .on .

  • Improvement methods refresh , create , pagecreate and updatelayout are intended for use on the current page (active page is $.mobile.activePage ) for re-applying the jQuery Mobile style. For pages created dynamically and located in the DOM, there is no need to use any improvement method - not even .page() or pagecreate - because the pages and their contents will be expanded after placement in the DOM.

+6
source

Since you add the expandable class se to the class dynamically, it cannot be updated because it is not created. you need to create it.

you should use

 $(".childnev").html(list).trigger('create'); 
+1
source

The shot set is not initialized. You are replacing html, so you need to call create on the element.

Replace $(".childnev").collapsibleset('refresh');

with

 $(".childnev").trigger('create'); 

The update method is used only for dynamic adding, deleting an element.

+1
source

What it costs: I ran into a problem when I tried to modify the contents of an existing collapsible div using .html (). It would not reflect properly on anything. But replacing this div (also copying its "id") with replaceWith (), then the trigger ("create") worked fine.

0
source

Source: https://habr.com/ru/post/1488829/


All Articles