1

Using jQuery Mobile I would like to generate pages using the json below. By generate I mean this json represents the layout and the structure of the whole mobile site. I somehow want to loop over this data (client site) and create the home page with page list and page. Can someone get me started with this with an example.

Many thanks

{
    "name": "My Site Name",
    "logo": "",
    "theme": "a",
    "fullSiteLink": "http://www.google.com",
    "pages": [
        {
            "id": "1364666933727",
            "name": "I'm a page",
            "type": "basic",
            "components": {
                "img": "url here",
                "text": "This is the page content."
            }
        }
    ]
} 
4

3 回答 3

1

Try to start by firstly making up a page how you think it should look like, then make some placeholders and write a script that feills them with data from your JSON.

于 2013-03-30T18:29:57.123 回答
1

You should also have a look at using requireJs alongside JQM. If you store your pages (or page elements) as templates, you can easily pull them in via the !text plugin and then loop over your JSON to fill the necessary data.

Has the added benefit of your page/widget templates being cached after having them requested the first time.

于 2013-03-30T18:40:42.263 回答
1

To get JSON array, use $.ajax.

$.ajax({
 Type: "GET",
 url: URL,
 dataType: "json",
 contentType: "application/json",
  success: function(data) {
  $.each(data, function(index, value) {
   // your code here
   });
  }
});
于 2013-03-30T19:19:03.070 回答