8
嗨,我試圖在jinja模板中填充Google Visualization api。 我把樣品參數,並將其傳遞給API 但單引號和雙引號轉換爲'和& 下面是腳本:Jinja模板渲染雙引號或單引號爲' "
<script type="text/javascript">
//load the Google Visualization API and the chart
google.load('visualization', '1', {'packages': ['columnchart']});
//set callback
google.setOnLoadCallback (createChart);
//callback function
function createChart() {
//create data table object
var dataTable = new google.visualization.DataTable();
//define columns
dataTable.addColumn('string','Quarters 2009');
dataTable.addColumn('string', 'Earnings');
//define rows of data
// answerjson=answerjson.replace("'",'"');
{% set answerjson1='[["1": "Saturday"], ["6": "Sunday"], ["1": "Wednesday"], ["1": "Monday"], ["1": "Monday"], ["1": "Tuesday"], ["1": "Sunday"]' %}
dataTable.addRows({{answerjson1}});
//instantiate our chart object
var chart = new google.visualization.ColumnChart (document.getElementById('chart'));
//define options for visualization
var options = {width: 400, height: 240, is3D: true, title: 'Company Earnings'};
//draw our chart
chart.draw(dataTable, options);
}
</script>
這裏是傳遞給API
輸入請幫助我,我需要做什麼。
由於這個工作。我正在嘗試{{answerjson1 | e}} – shobhit
這個答案指出了我的文檔,在那裏我找到了過濾器tojson,它符合我的需求:) – paranoidhominid