2011-11-28 3 views
0
내가 모듈로 jQuery1.7를로드 할 필요

으로 CDN에서 jquery1.7로드되지 않습니다, 나는 @jrburke의이 코드를 본 적이 .js 이름은 서버 쪽에서 생성됩니다. PHP 배열에서 가져 왔습니다.Requirejs 모듈

require(['http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'], 
     function($) { 
    //$ points to jQuery 
}); 

그러나 $이 함수 내에서 널 :

그래서, 난이 썼다.

UPDATE : 여기

이 페이지 내 JS-스크립트 렌더링 내 PHP 템플릿입니다 :

<script src="http://requirejs.org/docs/release/1.0.1/minified/require.js"> 
</script> 

<script> 
    require([ 
     <?php echo "'". implode("',\n\t'", $this->scripts) . "'\n"; ?> 
    ], function($){ 

     console.warn ($); // null ;(

     // loaded jQuery 
     window.$ = $; 

     // Load main client script for this page 
     boot('<?php echo $this->eprint($this->content_page); ?>'); 

    }); 
</script> 

과이 페이지 (페이지 index) 내 PHP 배열입니다 :

:
$scripts = array(
    'http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js', 
    'http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js', 
    '/js/libs/jquery.history.js?v=1321687090', 
    '/js/libs/coolclock.js?v=1321629683', 
    '/js/libs/excanvas.js?v=1321629683', 
    '/js/client.modules.js?v=1321703735', 
    '/js/client.all.js?v=1322512192', 
    '/js/boot.js?v=1322512037', 
    '/js/client.index.js?v=1321689884' 
); 
+0

가능한 중복 (http://stackoverflow.com/questions/8070959/sourcing-jquery-from-a-cdn) – Bevan

답변

1

양식의 당신의 PHP 배열을 가지고3210
$jquery = array (
    'jQuery' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js' 
); 

그런 시도 :

requirejs.config({ 
    paths: <?php echo json_encode($jquery) ?> 
}); 

require(['jquery'], function($) { 
    //$ points to jQuery 
}); 
[?를 CDN에서 소싱 jQuery를]의
+0

I를 내 질문을 업데이 트했습니다. 'php' 코드 –

+1

@Innuendo가 추가되어 여러분의 삶이 마술처럼 쉬워 질 것입니다 :-) – Neal

+0

그래서'requirejs.config'의'paths' prop에 제 배열의 모든 요소를 ​​추가 할 수 있습니까? 그것은 정상입니다. 그것들 모두가 모듈 형태는 아닙니다. 그렇지 않습니까? –