MarkO
MarkO

Reputation: 795

Generating Jquery Mobile site from Json

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."
            }
        }
    ]
} 

Upvotes: 1

Views: 117

Answers (3)

Omar
Omar

Reputation: 31732

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
   });
  }
});

Upvotes: 1

frequent
frequent

Reputation: 28513

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.

Upvotes: 1

Ale
Ale

Reputation: 2022

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.

Upvotes: 1

Related Questions