简体   繁体   English

未捕获的TypeError:$(…).ddBarChart不是函数

[英]Uncaught TypeError: $(…).ddBarChart is not a function

Working on MVC 5 project. 正在从事MVC 5项目。 This particular page is a partial page (Razor), if that makes any difference. 如果有任何不同,此特定页面是部分页面(剃刀)。

I'm trying to utilize a ddchart jQuery library. 我正在尝试利用ddchart jQuery库。 ( http://kiersimmons.com/ddchart/index.html ) I keep getting this error... http://kiersimmons.com/ddchart/index.html )我一直收到此错误...

Uncaught TypeError: $(...).ddBarChart is not a function

The line of code that the error is happening on is here: 错误发生的代码行在这里:

$("#chart_div_static").ddBarChart({
        chartDataLink: "~/Scripts/plugins/ddchart/Chart_Data.js?1=10",
        action: 'init',
        xOddClass: "ui-state-active",
        xEvenClass: "ui-state-default",
        yOddClass: "ui-state-active",
        yEvenClass: "ui-state-default",
        xWrapperClass: "ui-widget-content",
        chartWrapperClass: "ui-widget-content",
        chartBarClass: "ui-state-focus ui-corner-top",
        chartBarHoverClass: "ui-state-highlight",
        callBeforeLoad: function () { $('#loading-Notification_static').fadeIn(0); },
        callAfterLoad: function () { $('#loading-Notification_static').stop().fadeOut(0); },
        tooltipSettings: { extraClass: "ui-widget ui-widget-content ui-corner-all" }
    });

I know the function exists and the reference (to the js file that contains the function) is placed before ddBarChart is called. 我知道该函数存在,并且在调用ddBarChart之前放置了对(包含该函数的js文件的)引用。 FYI the reference is.... 仅供参考。

<script src="~/Scripts/plugins/ddchart/jquery.ddchart.js"></script>

As a test: In my jquery.ddchart.js file I even made a test() function that simply pops up an alert. 作为测试:在我的jquery.ddchart.js文件中,我什至做了一个test()函数,该函数只是弹出一个警报。 I wrote this function on the line before the ddBarChart function. 我在ddBarChart函数之前的那一行写了这个函数。 When I call the test function it works fine. 当我调用测试功能时,它可以正常工作。 So I know the reference to the external js file (jquery.ddchart.js) is correct. 因此,我知道对外部js文件(jquery.ddchart.js)的引用是正确的。

**** Update **** ****更新****

FYI: The ddBarChart function, in the external file, starts off as... 仅供参考:外部文件中的ddBarChart函数以...开头

jQuery.fn.ddBarChart = function(options) {
        function setupDrillDown(strID, intDelay, strH, strW, strL) {
            $(strID+ "> .ddchart-chart-final").css("z-index","2");
               :
               :
        }

        function aniDrillDown(strID,intDelay) {
            $(strID+ " > .ddchart-chart-final > .ddchart-chart-wrapper-sub").animate( {width: "100%",height: "100%",left: "0%"}, intDelay-500, function(){aniCleanUp(strID)});  
        }
               :
               :

**** Update Note **** (This is a MVC 5 partial page (razor), if that makes any difference. Seemed to work when I created a normal non-partial page in a different project.) ****更新说明****(这是MVC 5的部分页面(剃刀),如果有什么区别。当我在其他项目中创建普通的非部分页面时,它似乎可以工作。)

Any ideas what this could be? 有什么想法吗? Thanks! 谢谢!

I've encountered a problem like this before. 我以前遇到过这样的问题。 The problem was that the jQuery library was being included twice. 问题是jQuery库被包含两次。

This happened in the following order: 这按以下顺序发生:

  • The HTML file loaded the jQuery file, defining the jQuery object. HTML文件加载了jQuery文件,定义了jQuery对象。
  • The HTML file loaded the plugin file, attaching a function to jQuery.fn HTML文件加载了插件文件,将一个函数附加到jQuery.fn
  • The HTML file loaded the jQuery file, redefining the jQuery object. HTML文件加载了jQuery文件, 重新定义了jQuery对象。

After this, any references to jQuery will be on the newly defined jQuery object, which does not have the plugin function attached to it. 此后,对jQuery的所有引用都将在新定义的jQuery对象上,该对象没有附加的插件功能。

This would be consistent with it only failing when included from a partial view. 这仅在从局部视图包含时失败会与之保持一致。 You have to ensure the plugin is included only after the single jQuery source is included. 您必须确保仅在包含单个 jQuery源之后才包含该插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM