【发布时间】:2011-11-28 21:37:47
【问题描述】:
我需要将jQuery1.7加载为模块,我看过@jrburke的这段代码:
requirejs.config({
paths: {
'jquery' : 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min'
}
});
require(['jquery'], function($) {
//$ points to jQuery
});
它对我来说不是很有用,因为所有.js 名称都是由服务器端生成的,我是从 php-array 中获取的。
所以,我写了这个:
require(['http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'],
function($) {
//$ points to jQuery
});
但$ 在此函数中为空。
更新:
这是我的 php 模板,它为此页面呈现我的 js 脚本:
<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-array:
$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'
);
【问题讨论】:
标签: php jquery requirejs js-amd