2013-07-16 1 views
1

ExtJS 프로젝트와 함께 사용하려는 다른 프로젝트에서 사용하는 몇 가지 jQuery 기반 JavaScript 라이브러리가 있습니다. 다른 프로젝트는 일반적으로 RequireJS를 통해 동적으로 이러한 라이브러리를로드ExtJS로 바닐라/jQuery 라이브러리를 동적으로로드하고 사용하는 방법

define(['lib/api/client', 'lib/my_lib'], function(ApiClient, MyLib) { 
    ... 
}); 

것은 이제 내의 ExtJS 프로젝트에이 라이브러리를 사용하기를 원하는 경우를 생각 해보자. ExtJS에서 이것을 수행 할 수있는 "표준"방법이 있습니까? 아니면 이처럼 내 솔루션을 준비해야합니까? 이 문제에 대한 일반적인 접근 방식은 무엇입니까?

require([ 
    'lib/extjs/ext-all', 
    'lib/api/client', 
    'lib/my_lib' 
], function(Ext, ApiClient, MyLib) { 

    Ext.application({ 
    name: 'MyApp', 
    appFolder: 'app', 
    launch: function() { 
     var apiClient = new ApiClient(); 

     Ext.create('MyApp.view.Main', { 
     apiClient: apiClient 
     }); 

     MyLib.doSomething(); 
    } 
    }); 

}); 

그리고

require(['lib/extjs/ext-all'], function(Ext) { 
    Ext.define('MyApp.view.Main', { 
    ... 
    }); 
}); 

결론은 :

<head> 

<script src="lib/api/client" type="text/javascript"></script> 
<script src="lib/my_lib" type="text/javascript"></script> 
<script src="lib/my_other_lib" type="text/javascript"></script> 
<script src="lib/another_lib" type="text/javascript"></script> 
<script src="lib/and_another_lib" type="text/javascript"></script> 
<script src="lib/and_yet_another_lib" type="text/javascript"></script> 

</head> 

그리고 의존성 관리를 원하는 : 나는 머리에 스크립트 태그의 톤을 피하기 위해합니다.

답변

1

Ext.Loader.loadScript 메서드 (api)를 사용할 수 있습니다. 다음과 같이 코드를 구성 할 수 있습니다.

Ext.Loader.loadScript('lib/api/client'); 
Ext.Loader.loadScript('lib/my_lib'); 

Ext.onReady(function() { 
    // setup your Ext JS app here, external libraries are loaded. 
}); 
+0

머리에 스크립트 태그 이상이 있습니다. 그러나 종속성 관리를 사용하는 것이 좋을 것입니다. 예를 들어, my_lib는 my_other_lib에 의존하고 my_other_lib가 먼저로드되도록합니다. –

관련 문제