我已经安装了https://github.com/yiisoft/yii2-jui,但是我如何手动加载Javascript库而不使用服务器端代码来制作小部件?
在我的情况下,我只需要sortable()
函数可用于我拥有的一些现有代码。我只想把它放在特定的页面上,而不是所有的页面上。所以不能直接加到AppAsset.php
您可以在布局视图或控制器中添加检查,以添加对当前页面的检查:
if(Yii::$app->controller->id == 'foo' && Yii::$app->controller->action->id == 'bar')
{
// for inside controller check
$this->registerJs("your_js_file_path");
}
... html here ...
<?
if(Yii::$app->controller->id == 'foo' && Yii::$app->controller->action->id == 'bar')
{?>
<!-- for inside controller check -->
<script src=""></script>
<?}?>
... html here ...