2015-10-19 45 views

回答

1

您可以使用helpersHandlebars這樣的:http://jsfiddle.net/sandenay/2hg9qcdL/1/

HTML:

<div class="body"> 
    {{#Relation}} 
    {{#getword this}}{{/getword}} 
    {{/Relation}} 
</div> 

助手:

Handlebars.registerHelper('getword', function(a,opts) { 


     return (a[1]); 

    }); 
+1

非常感謝。它根據我的需要工作。 – xxCodexx

1

可以遍歷你的對象,並創建一個單獨的數組:

var values = [] 
obj.Relation.forEach(function(el){ 
    values.push(el[1]); 
}); 
console.log(values); // ["one", "two", "Three", "Four"] 
+0

這是很好的答案,但我想與handlebar.js – xxCodexx