json2html - Why is thing displaying to the page with this code? -


my json good. i've followed simple example json2html site ... nothing displays.

<script type="text/javascript">            $.getjson( "news/list/category/news/format/json",  function(data) {          var transforms = {   stories: [      {'<>':'ul','class':'stories','html':function() {          return($.json2html(this.groups,transforms.group));      }}   ],   group: [    {"<>": "li", "id":"id", "html":[      {"<>": "span", "html": "${author} ${headline}"}      ]}   ]  };     $('#stories').json2html(data, transforms.stories);    })    </script> 

firstly if paste actual json in question go along way helping figure out issue.

this you're going wrong

stories: [     {'<>':'ul','class':'stories','html':function() {         return($.json2html(this.groups,transforms.group));     }}  ], 

let me run though how works

first

$('#stories').json2html(data, transforms.stories); 

transforms data object(s) stories

stories: [     {'<>':'ul','class':'stories','html':function() {         return($.json2html(this.groups,transforms.group));     }}  ], 

stories transforms objects under "groups" property group

group: [   {"<>": "li", "id":"id", "html":[     {"<>": "span", "html": "${author} ${headline}"}     ]}  ] 

group transforms group object list item span.

so you're json object better like

[{"groups":[{"author":"someone","headline":"someheadline"},..]}] 

though since groups used example suspect json object looks more (best paste actual json in question)

[{"author":"someone","headline":"someheadline"},..] 

in case use the following code snipet should work. keep in mind transform representation of html (template) want each object in json array $.getjson

var data = [{"author":"someone","headline":"someheadline"}];  var transforms = {  story: [   {"<>": "li", "id":"id", "html":[     {"<>": "span", "html": "${author} ${headline}"}     ]}  ]};  $("#stories").json2html(data,transforms.story);  //or using getjson $.getjson( "news/list/category/news/format/json",  function(data) {      $('#stories').json2html(data, transforms.story); }); 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -