[英]How to access value in context object with key in Handlebars?
我有一個看起來像這樣的車把模板:
<script id="user-template" type="text/x-handlebars-template">
<a class="result" href="/{{github_id}}">
<img src="{{image_url}}" />
<span class='additional-name'>{{> highlight object=this key="github_id"}}</span>
</a>
</script>
我的highlight
部分看起來像:
<script id="highlight-search-partial" type="text/x-handlebars-template">
{{#if object._highlightResult}}
{{#if object._highlightResult.key}}
{{object._highlightResult.key.value}}
{{/if}}
{{else}}
{{object.key}}
{{/if}}
</script>
這是我的javascript對象的樣子:
渲染車把模板后,視覺上它是空的。 什么都沒有呈現。
關於我在做什么錯的任何想法嗎? 我正在使用3.0.3(最新)把手。
我最終編寫了一個輔助車把功能:
<span>{{highlight this "github_id"}}</span>
Handlebars.registerHelper('highlight', function(obj, field) {
if (obj['_highlightResult']) {
return obj['_highlightResult'][field].value;
} else {
return obj[field];
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.