I can't find the answer to this, I've read JQM docs and stackoverflow questions.
I have a listview #lista-principal
that needs exactly the same split-buttons
The split-button open-up a popup that let the user choose the class to be inserted. The insertion happens via jquery using $('a.ui-li-link-alt').on('click'...
Here is the JSBin: http://jsbin.com/akerav/15/edit (click on header to trigger problem)
As the split-buttons are all equal, I wish to insert then programatically. I cannot find a way to do it so the split-buttons get refreshed by JQM.
What would be correct way of programatically inserting split-buttons in JQM pages ?
For testing purposes, I've put the problematic code in this click function:
$('div[data-role="header"]').click( function() {
var split_button = $('<a></a>')
.attr({
'data-rel':'popup',
'data-position-to':'origin',
'data-transition':'slidedown'
})
.html('Vistoria');
var newli = $('ul#lista-principal li').clone();
newli.find('a').append(split_button);
$('ul#lista-principal li').remove();
$('ul#lista-principal').append(newli);
newli.trigger('create');
$('ul#lista-principal').listview('refresh');
});
mar/19 findings (this is twilight zone, corrections are welcome)
- Looks like split-buttons dont get enhanced programatically if you put the second
<a>
inside the first one (although it works if you set it on the pure HTML); - If you need to modify a bunch of
<li>s
already in the HTML, you'd better do it onpagebeforecreate
becauselistview('refresh')
doesn't affect already enhanced itens and you should redo your entire list to use listview('create'); - This is almost what I was looking for: http://jsfiddle.net/ffabreti/Q4SCt/1/
(based on http://jsfiddle.net/Gajotres/LrAyE/)
Answer to the question Finally, found a way to insert split-buttons after pagecreate:
- On
pagecreate
set a global variable with you original list content - Hook a event to alter the list ( example,
$("div[data-role='header']").on('click'...
) - Clone your original-list and edit it
- replace the content of your list with the edited content
- refresh de listview component
- you can see the full code here: http://jsfiddle.net/ffabreti/Hyams/11/