tbo*_*hev 1 jquery visual-studio jqplot knockout.js
我正在开发一个Web应用程序,我非常喜欢JQPlot提供的拖动图.我在他们的网站上提到了这个例子:http: //www.jqplot.com/deploy/dist/examples/customHighlighterCursorTrendline.html
据我所知,为了让JQPlot正常工作,我需要包含jQuery,jQuery jqplot函数和一些样式文件.JQPlot下载提供了自己的jquery.js和jquery.jqplot.js.
另外,我也使用Knockout.js作为这个项目的一部分,我将包含标准的jquery-1.9.1.js文件以使其正常工作.
但是,"$"的定义文件是jquery-1.9.1.js,并且由于JQPlot提供了自己的jQuery文件,因此必然存在某种冲突,使jqplot函数无法识别.这有解决方法吗?这是我的HTML代码:
@model FluidBedSimulation.Models.BedState
@using Newtonsoft.Json
@{
    ViewBag.Title = "Index";
}
<script type="text/javascript" src="../Scripts/jqPlot/jquery.min.js"></script>
<script type="text/javascript" src="../Scripts/jqPlot/jquery.jqplot.js"></script>
<script type="text/javascript" src="../Scripts/jqPlot/plugins/jqplot.dateAxisRenderer.min.js"></script>
<script type="text/javascript" src="../Scripts/jqPlot/plugins/jqplot.barRenderer.min.js"></script>
<script type="text/javascript" src="../Scripts/jqPlot/plugins/jqplot.categoryAxisRenderer.min.js"></script>
<script type="text/javascript" src="../Scripts/jqPlot/plugins/jqplot.cursor.min.js"></script>
<script type="text/javascript" src="../Scripts/jqPlot/plugins/jqplot.highlighter.min.js"></script>
<script type="text/javascript" src="../Scripts/jqPlot/plugins/jqplot.dragable.min.js"></script>
<script type="text/javascript" src="../Scripts/jqPlot/plugins/jqplot.trendline.min.js"></script>
<link rel="stylesheet" type="text/css" href="../Scripts/jqPlot/jquery.jqplot.min.css" />
<h2>Index</h2>
@if (false)
{
    <script src="../../Scripts/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="../../Scripts/knockout-2.2.0.js" type="text/javascript"></script>
    <script src="../../Scripts/knockout.mapping-latest.js" type="text/javascript"></script>
}
<script src="@Url.Content("~/Scripts/jquery-1.9.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/knockout-2.2.0.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/knockout.mapping-latest.js")" type="text/javascript"></script>
<script type ="text/javascript">
    $(document).ready(function () {
        $.jqplot.config.enablePlugins = true;
        s1 = [['23-May-08', 1], ['24-May-08', 4], ['25-May-08', 2], ['26-May-08', 6]];
        plot1 = $.jqplot('chartdiv', [s1], {
            title: 'Highlighting, Dragging, Cursor and Trend Line',
            axes: {
                xaxis: {
                    renderer: $.jqplot.DateAxisRenderer,
                    tickOptions: {
                        formatString: '%#m/%#d/%y'
                    },
                    numberTicks: 4
                },
                yaxis: {
                    tickOptions: {
                        formatString: '$%.2f'
                    }
                }
            },
            highlighter: {
                sizeAdjust: 10,
                tooltipLocation: 'n',
                tooltipAxes: 'y',
                tooltipFormatString: '<b><i><span style="color:red;">hello</span></i></b> %.2f',
                useAxesFormatters: false
            },
            cursor: {
                show: true
            }
        });
    });
</script>
@*grab values from the view model directly*@
<p>Bed Weight: <strong data-bind="text: BedMass" id="BedMass"></strong></p>
<p>H2O Bed Weight: <strong data-bind="text: BedWaterMass" id="BedWaterMass"></strong></p>
<p>Fraction of Binder in Spray Solution: <strong data-bind="text: binderFraction" id="binderFraction"></strong></p>
<p>
    Enter the Bed Mass: 
            <input data-bind="value: BedMass" />
            @*Html.TextBoxFor(model => model.BedMass, new { data_bind = "value: BedMass" })*@
</p>
<p>
    Enter the H2O Mass in the Bed: 
            @Html.TextBoxFor(model => model.BedWaterMass, new { data_bind = "value: BedWaterMass" })
</p>
<p>
    Enter the Fraction of Binder in the Spray Solution: 
            @Html.TextBoxFor(model => model.binderFraction, new { data_bind = "value: binderFraction" })
</p>
<button data-bind="click: Simulate">Simulate</button>
@*to be used later as controls for the simulation*@
<div id="chartdiv" style="height:400px;width:300px; "></div>
<script type="text/javascript">
    this.BedMass = ko.observable(1);
    this.BedWaterMass = ko.observable(1);
    this.binderFraction = ko.observable(1);
    (function () {
        var model = '@Html.Raw(Json.Encode(Model))';
        var viewModel = ko.mapping.fromJS(model);
        ko.applyBindings(viewModel);
    })();
</script>
我在运行项目时得到的确切错误是:"Uncaught TypeError:无法读取未定义的属性'config'"这是触发它的行:
 $.jqplot.config.enablePlugins = true;
当我写"$"时.在Visual Studio中,jqplot甚至不是一个选项.我搜索了一堆线程,但似乎找不到任何相关的东西.我想知道是否有一些方法可以同时使用jqplot和knockout(以及其他使用标准jquery文件的东西).提前致谢!
我有同样的问题.我追踪了jquery.jqplot.js文件的处理并且它正在被执行,配置已经定义,并且在文件处理结束时,一切似乎都存在(即变量被正确分配给jQuery变量和$别名).但是,当我到达$(document).ready()回调时,似乎$.jqplot未定义......
我发现扩展名'noty'也出现了同样的问题......最后我注意到在我的Layout.cshtml末尾(我在MVC 4中实现)我发现有一个@RenderSection("scripts", required: false)在之前引用了JQuery包.
总结:jQuery包被包含在HTML的head部分(由我)中,然后再次包含在页脚中(它覆盖了html中包含的所有扩展<head>).这是MVC 4模板的一个特性 - 我并不喜欢这个模板.
| 归档时间: | 
 | 
| 查看次数: | 1400 次 | 
| 最近记录: |