"Bu"

2015-11-19 19 views
6

benim json böyle olduğunu düşünün boş dize ise çalışmaz tutma kollarında {{} bu #each}."Bu"

{{#each this}} 
    -- This is for main and secondary -- 
    {{#each this}} 
     -- This is for "" in case of main and "key" in case of secondary -- 
    {{/each}} 
{{/each}} 

Benim iç içe #each

+0

son zamanlarda, handlebars.js'nin daha yeni sürümüne geçtik. Bu sorunla ilgili bir şey yapması gerektiğinden emin değil. – ashy143

cevap

0

3.x.x gibi görünüyor "ana" özelliği için benim json gösterilen bu neden bir hata vardı "bu" boşsa çalışmayacaktır. 4.0.0'da Here's the commit that fixes this.

4.xx: Tamam

3.xx: Yeterli değil

2.0.0: Yeterli

var data = { 
 
    main: { 
 
    "": [1, 2, 3] 
 
    }, 
 
    secondary: { 
 
    "key": [3, 4, 5] 
 
    } 
 
}; 
 
var compiled = Handlebars.compile(document.getElementById('temp').innerHTML); 
 
document.write(compiled(data));
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.js"></script> 
 
<script id="temp" type="text/x-handlebars-template"> 
 
    {{#each this}} 
 
    {{@key}}<br> 
 
    {{#each this}} 
 
     &nbsp;&nbsp;"{{@key}}": {{this}}<br> 
 
    {{/each}} 
 
    {{/each}} 
 
</script>

aşağıda snippet'iyle bu sürümleri kontrol