使用 Handlebars JS 时如何向 div 添加属性?

How to add attribute to div, when using Handlebars JS?

我正在使用 Handlebars JS 从模板中添加元素。 Handlebar 模板如下所示:

<script id="item-template" type="text/x-handlebars-template">
    <div class="case-item">{{title}}</div> 
</script>

脚本

// create a handlebars template
var source = document.getElementById('item-template').innerHTML;
var template = Handlebars.compile(source);

数据集

var items = new vis.DataSet([{        
    title: 'This is a test title'
}

结果

当我 运行 代码时,<div class="case-item"> 仅显示 <div> 它不会创建属性 class="case-item"

<div>This is a test title</div>

而不是

<div class="case-item">This is a test title</div>

知道它为什么“剥离”属性吗?

我找到了另一个解决方案,解决了问题中描述的车把问题。

我选择关注Vis Timeline Custom Styling example