Yii多次加载jQuery [英] Yii loading jquery multiple times
本文介绍了Yii多次加载jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有一个页面可以呈现6个局部视图.我现在面临的问题是,因为我需要将processOutput设置为TRUE,因此会多次加载jquery.
I currently have a page which renders 6 partial views. The problem that I am now facing is that, because I need to set processOutput to TRUE, jquery is loaded multiple times.
我试图通过添加来解决此问题
I tried to resolve this by adding
<?php Yii::app()->clientscript->scriptMap['jquery.min.js'] = FALSE; ?>
<?php Yii::app()->clientscript->scriptMap['jquery.js'] = FALSE; ?>
以我的部分观点.问题在于,这样做不会使jquery完全加载AT.
To my partial view. The problem is, that by doing so, jquery doesn't load AT all.
是否可以解决此问题,使其仅加载一次?
Anyway to resolve this so it will only load once?
推荐答案
将代码更改为:
<?php $jquery = '/js/jquery.min.js'; ?>
<?php Yii::app()->clientscript->scriptMap['jquery.min.js'] = $jquery; ?>
<?php Yii::app()->clientscript->scriptMap['jquery.js'] = $jquery; ?>
通过这种方法,您可以使用资产管理器.示例:
With this approach, you can use the asset manager. Example:
<?php $jquery = Yii::app()->assetManager->publish(Yii::app()->theme->basePath . '/assets/jquery-1.9.1.js'); ?>
<?php Yii::app()->clientscript->scriptMap['jquery.min.js'] = $jquery; ?>
<?php Yii::app()->clientscript->scriptMap['jquery.js'] = $jquery; ?>
这篇关于Yii多次加载jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文