0

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.results[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

2
  • 1
    can you show the other button code you're referring to as well as the css that should be applied to these links? Commented May 23, 2011 at 7:04
  • may be you need to render not <a> but <button> or <input type='button'> ? Commented May 23, 2011 at 8:35

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks the $('#dPlaces').page(); after the loop worked, but something weird is that the 2nd time it does not work as desired :-/
you may need to add it to a .live() jquerymobile.com/demos/1.0a4.1/#docs/api/events.html
You mean, add the .Page() to the live()? I changed to be used with simple <p>My text</p> and a </hr> to divide.. but will like to test with buttons, thanks..
if you're transitioning to a new page you need to encapsulate the code above inside a .live event. See update

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.