在Ext JS 4中加载外部脚本

时间:2015-04-22 04:42:19

标签: javascript extjs

在Ext JS 4中,我需要加载D3 API。我使用以下代码



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


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




但是,在浏览器控制台中,我收到以下错误 -

未捕获的ReferenceError:未定义onLoad

有人可以帮我纠正上述代码吗?

谢谢。

1 个答案:

答案 0 :(得分:2)

使用this.onLoadthis.onError,如下所示:

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

(你也可以通过范围)