Jquery Dynamically generated buttons no css
I am fetching some data from a Google Places Api, I am using jquerymobile to show a user nearest places, the data comes in JSON I want to generate a set of buttons so is easy for user to click selected location.
The data is generated but the button is showed as a link with no style, even is the same code of another button with style. here is the code snippet.
$.each(pdata.results, function(key) {
if (key>0 && key<6) {
$('#dPlaces').append('<a href="#" data-role="button">'+pdata.re开发者_运维百科sults[key].name+'</a>');
} //endif
}); //each
Data is returned but no Button style.. the idea is I will put a onclick() to set some value and way a list of buttons but with JQM style.
thanks.
Norman
You need to refresh the page, try something like this:
$.each(pdata.results, function(key) {
if (key>0 && key<6) {
$('#dPlaces').append('<a href="#" data-role="button">'+pdata.results[key].name+'</a>').page();
} //endif
});
or maybe:
$.each(pdata.results, function(key) {
if (key>0 && key<6) {
$('#dPlaces').append('<a href="#" data-role="button">'+pdata.results[key].name+'</a>');
} //endif
});
$('#dPlaces').page();
UPDATE:
$('div').live('pageshow',function(event, ui){
$.each(pdata.results, function(key) {
if (key>0 && key<6) {
$('#dPlaces').append('<a href="#" data-role="button">'+pdata.results[key].name+'</a>');
} //endif
});
$('#dPlaces').page();
});
Docs: http://jquerymobile.com/demos/1.0a4.1/#docs/api/events.html
精彩评论