dojo中not a function错误如何处理?

发布于 2024-10-09 04:42:35 字数 980 浏览 0 评论 0原文

我在 dojo 中的 callChart 函数中收到not a function error。我正在开发一个网站,它使用 excanvas 在浏览器上绘制一些图表。

在页面加载时,我进行了一次 Ajax 调用,该调用获取一些数据库值并将它们传递给 callChart:function(),此 callChart 函数调用 excanvas 进行图表绘制。但在这里我得到了callChart is not a function

代码片段如下:

onload 我正在执行

 drawChart : function(){     
     this.chart(true);     
 },

chart: function(flag){
 dojo.xhrPost( {
 url : "/charting.html", 
 load : function(data){
          loadChart(data);
},
 error : function(error){
         console.error(" occured while fetch chart" );
    }
  } );

并且在成功回调方法中

loadChart : function(response){
        this.callChart(response);

},

这是我的callChart,

callChart:function(chartData){
----
----
},

当我调用this.callChart(响应)时,我收到firebug错误“this .callChart(response) 不是函数”。

非常感谢任何帮助、指导或建议。

I am getting not a function error for my callChart Function in dojo. I am developing a website, which uses excanvas to paint some charts on the browser.

On page load I am having one Ajax call which fetches some database values and passes them to callChart:function(), this callChart function call excanvas for charting. But here I am getting callChart is not a function.

Code snippet is like below:

onload I am having executing

 drawChart : function(){     
     this.chart(true);     
 },

chart: function(flag){
 dojo.xhrPost( {
 url : "/charting.html", 
 load : function(data){
          loadChart(data);
},
 error : function(error){
         console.error(" occured while fetch chart" );
    }
  } );

And in success callback method

loadChart : function(response){
        this.callChart(response);

},

and this is my callChart,

callChart:function(chartData){
----
----
},

When I am calling this.callChart(response), I am getting firebug error "this.callChart(response) is not a function" .

Any help, guidance or suggestions are highly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅此而已 2024-10-16 04:42:35

你的“this”是回调机制(dojo.Deferred)。使用 dojo.hitch 修复上下文:

chart: function(flag){
 dojo.xhrPost( {
 url : "/charting.html", 
 load : dojo.hitch(this, function(data){ // changed this line
          this.loadChart(data); // added "this"
 }); // close paran
}

Your "this" is the callback mechanism (dojo.Deferred). Use dojo.hitch to fix the context:

chart: function(flag){
 dojo.xhrPost( {
 url : "/charting.html", 
 load : dojo.hitch(this, function(data){ // changed this line
          this.loadChart(data); // added "this"
 }); // close paran
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文