javascript - Accessing outer array values from inner array in Mustache.js / ICanHaz -


i have following json, outer array of objects (outer), each of may contain inner array of objects (inner):

{ "outer": [{"outername": "outername1",              "inner": [{"innername": "innername1"},                         {"innername": "innername2"}]             },             {"outername": "outername2",              "inner": [{"innername": "innername3"},                         {"innername": "innername4"}]             }] } 

i have icanhaz template builds unordered list. there must list item each object in each inner array.

<script type="text/html" id="tmp">     <ul>         {{#outer}}         {{#inner}}         <li>             {{outername}} - {{innername}}          </li>         {{/inner}}         {{/outer}}     </ul> </script> 

the problem is, doesn't seem possible reference outername within #inner condition. therefore output looks this:

 - innername1  - innername2  - innername3  - innername4 

when i'm expecting :

outername1 - innername1 outername1 - innername2 outername2 - innername3 outername2 - innername4 

does know how can resolve this? or have restructure json inner array contains outername?

that's valid mustache. problem in version of library.

icanhaz ships mustache.js v0.4.0. current version — eight releases , sixteen months later — is 0.7.2. switch icanhaz-no-mustache.js, , bring own mustache. should fix it.

here's fiddle of template working latest version of mustache.js:

var tpl  = $('#tpl').html();  var data = { "outer": [{"outername": "outername1",              "inner": [{"innername": "innername1"},                         {"innername": "innername2"}]             },             {"outername": "outername2",              "inner": [{"innername": "innername3"},                         {"innername": "innername4"}]             }] };  $('#output').html(mustache.to_html(tpl, data)); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -