2015-04-22 127 views
1

在Ext JS 4中,我需要加载D3 API。我使用下面的代码在Ext JS中加载外部脚本4

loadScript: function(callback, scope) { \t \t console.log('5) loadScript called');  
 
\t \t Ext.Loader.injectScriptElement('http://d3js.org/d3.v3.js', onLoad, onError); 
 
\t  console.log('D3 script loaded '); 
 
    }, 
 

 

 
    onError : function() { 
 
\t \t console.log('On Error'); 
 
\t }, 
 
\t onLoad : function() { 
 
\t \t console.log('On Load'); 
 
\t \t d3.select('body').append('div').style('position', 'absolute').style('padding', '0 10px').style('background', 'red').style('opacity', 0); 
 
\t },

然而,在浏览器控制台,我得到下面的错误 -

未捕获的ReferenceError:的onLoad没有定义

能有人帮我纠正上述代码?

谢谢。

回答

2

使用this.onLoadthis.onError,像这样:

Ext.Loader.injectScriptElement('http://d3js.org/d3.v3.js', this.onLoad, this.onError, this); 

(您可以通得过范围)

+0

谢谢。这解决了这个问题。 – kayasa