我试图使用下划线打印json对象,但它没有显示。如果我使用下划线的默认模板,它可以工作,但由于我使用JSP,我不能使用默认模板作为下划线。我尝试更改它,以便{{}}作为我的模板。
我有以下templateSettings:
<script type="text/javascript">
_.templateSettings = {
evaluate: /\{\{#(.+?)\}\}/g,
interpolate: /\{\{([^#].*?)\}\}/g
};
</script>
我的json文件看起来像
{
"input": {
"birthday": "Birthday"
},..
} 我的模板文件是:
<script type = "text/template" id ="name">
Name2: {{ name2 }} // prints [object Object]<br />
Name2.input: {{ name2.input }} //doesnt print <br />
Name2.input.birthday: {{ name2.input.birthday }} //doesnt print
</script>
正则表达式有问题吗?