android - json file to handlebars -


i developing android app framework7 show info vehicles. first screen contain list vehicles types , user can choose 1 type , go next screen subcategories.i want show contexts of each set in website using handlebars "{{}}". did first screen types wondering if possible use handlebars show subcategories of each vehicle type in different row(which user press , take him next page, have info subtype user selected).
have json file following code:

    [     { "id" : 1,       "vehicle type": "hatchback"       "subtypes": "st1", "st2", "st3"     },     { "id" : 1,       "vehicle type": "motorcycle"       "subtypes": "mt1", "mt2", "mt3"     }     ] 

if want use handlebars {{}}, need have template

  1. for example:

    <script id="template" type="text/template7">     {{#each records}}         <p>vehicle type is:  {{vehicle type}} </p>     {{/each}} </script> 
  2. compile template template7:

    var template = $$('#template').html(); var compiledtemplate = template7.compile(template); 
  3. get json data server:

    $$.getjson('link/to/your/json', {}, function (data) {               var context = data; } 
  4. now render compiled template passing required context

    var html = compiledtemplate(context); 

now, html variable contain html need. example:

    <p>vehicle type is: hatchback</p>     <p>vehicle type is: motorcycle</p> 

n.b. code has not been tested. , 'records' in first step needs replaced root node in json file.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -