SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2014
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JSON object is all nested in an array

    Hi,

    I'm working with mustache to convert a JSON to html.

    The sample code all works fine but now i'm implementing the actual JSON from the 3rd party its not working as its all being returned in one []

    Code:
    var data = [ { depts: [
        {   name: "Engineering",
            employees: [
                {firstName: "Christophe", lastName: "Coenraets"},
                {firstName: "John", lastName: "Smith"}]
        },
        {   name: "Sales",
            employees: [
                {firstName: "Paula", lastName: "Taylor"},
                {firstName: "Lisa", lastName: "Jones"}]
        }]
    }];
    it's just the two brackets in bold above that stops it from working, can't edit the response from the 3rd party. Is there something simple I can do in the mustache template to fix this?

  2. #2
    SitePoint Member
    Join Date
    May 2014
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok fixed it, was very simple.

    Just needed an array value in the mustache call as below

    var html = Mustache.to_html(tpl, jsonData[0]);


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •