0

I'm trying to improve my JQueryMobile \ JavaScript skills by building a simple web app that gets a json file and loads the data from it into a clickable listview.

The goal is to select one of the li elements by clicking it using data-role="button", and a new page should be open in a form of a dialog page, by using the data-rel="dialog" attribute + attaching the id of the new page that should be opened by using <a href="#newPage" data-rel="dialog"></a>. I'm facing two problems:

  1. For some odd reason, only the first li cell is clickable, while it remains un-populated, as the other li cells are populated but not clickable.

  2. After I refresh the page, the ul breaks and shows all names from the json in one li element. enter image description here

update - thanks to Jithin Lukose i was able to deal with this issue using the following function:

complete: function() {
        $('#namesListView').listview('refresh');
    }

jQuery mobile code:

<div data-role="page" id="scientists">
    <div data-role="header"><h3>great scientists</h3></div>

    <div data-role="content">
            <div>
                <ul data-role="listview" data-inset="true" data-filter="true" id="namesListView">
                    <li data-role="button"><a href="#newPage" data-rel="dialog"></a></li>
                 </ul>
             </div>
     </div>
 </div>

javascript code:

$.ajax({
    url:"scientists.json",
    dataType:"json",
    type:"get",
    cache:"false",
    success:function(data){
        console.log(data);
        $(data.abc).each(function(index,value){
            console.log(value.name);
            $("#namesListView").append("<li>"+value.name+"</li>");
        });
    }
});

1 Answer 1

1

Try this answer.

https://stackoverflow.com/a/4998892/1640577

  complete: function() {
            $('#namesListView').listview('refresh');
        } 
Sign up to request clarification or add additional context in comments.

6 Comments

thanks, it worked, now the list doesnt break. still cant make rest of the list elements clickable.
$("#namesListView li").live('click',function(){ });
If you are using jQuery 1.9 + user $(document).on('click','#namesListView li',function(){ })
it actually detects the clicks, but why cant i use the "data-role="button" attribute to make all the "li" automatically clickable + automatic redirection to the next page via the "<a href="#newPage.." attribute?
Yes, You can use $("#namesListView").append('<li><a href="'+value.url+'">'+value.name+'</a></li>');
|

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.