我不知道为什么我总是遇到最奇怪的问题。我正在使用剑道 UI 图表。在 PartialView 中。当 PartialView 被 jQuery 调用时,它会在运行时生成 div 和一些 jQuery 代码。我将整个 div 和 JQ 代码附加到表行的单击行下方。问题是,它只附加了 div,它忽略了脚本标签及其代码,这是渲染图表所必需的。
我的部分视图是:
@(Html.Kendo().Chart()
.Name("XXXProducts")
.Title("XXX Products")
.Legend(legend => legend
.Visible(false)
)
.ChartArea(chartArea => chartArea
.Background("transparent")
)
.Series(series =>
{
series.Bar(Model.SalesAxis).Name("Total Sales");
})
.CategoryAxis(axis => axis
.Categories(Model.MonthsAxis)
.MajorGridLines(lines => lines.Visible(false))
)
.ValueAxis(axis => axis
.Numeric()
.Max(Model.SalesAxis.Max() + 100)
.Line(line => line.Visible(false))
.MajorGridLines(lines => lines.Visible(true))
)
.Tooltip(tooltip => tooltip
.Visible(true)
.Template("#= series.name #: #= value #")
)
)
我在其他页面上的 jQuery 代码来呈现视图:
function RenderChart(row) {
var rowIndex = $("#tblDetail").find($(row)).index() + 1;
var chartData = '';
$.get('@Url.Action("MonthlyChart", "Chart")', function (data) {
chartData = "<tr style='height:300px;'><td colspan='5'>" + data + "</td></tr>";
$('#tblDetail tr:nth-child(' + rowIndex + ')').after(chartData);
});
}
当我提醒“chartData”时,它显示以下内容:
<tr><td colspan='5'><div class="k-chart" id="XXXProducts"></div><script> jQuery(function(){jQuery("#XXXWaterProducts").kendoChart({"chartArea":{"background":"transparent"},"title":{"text":"Site Visitors Stats /thousands/"},"legend":{"visible":false},"series":[{"name":"Total Sales","type":"bar","data":[56000,74500,45000,86000,49850,63482,97600,63250,79860,42100,32010,89200]}],"categoryAxis":[{"majorGridLines":{"visible":false},"categories":["January","February","March","April","May","June","July","August","September","October","November","December"]}],"valueAxis":[{"majorGridLines":{"visible":true},"line":{"visible":false},"max":97700}],"tooltip":{"template":"#= series.name #: #= value #","visible":true}});});</script> </td></tr>
但是当我检查源代码时,它只显示:
<tr><td colspan='5'> <div class="k-chart" id="XXXProducts"></div></td></tr>
脚本标签无处可寻。