<分区>
我正在使用 python jinja2
将 json
传递到 HTML
文件中。我传递的 json
类似于下面,
result = { "config":{ "firstTitle" : "Report" } }
在我的 HTML
文件中,我有一个 javascript
函数,如下所示,它按预期工作,
function dispDetails()
{
//This works as expected
//It print 'Report' in the console
console.log('{{ config.firstTitle }}');
}
但是如果我的 javascript
函数被修改为包含一个 javascript 变量
,代码就会抛出错误,
function dispDetails()
{
//Error thrown : jinja2.exceptions.TemplateSyntaxError: expected name or number
titleStr = "firstTitle";
console.log('\'{{ config.'+titleStr+' }}\'');
}
我已经尝试了各种方法来使它正常工作,但不确定我哪里出错了,需要一些指导。