0
我已經安裝https://github.com/yiisoft/yii2-jui但我該如何手動加載Javascript庫而不使用服務器端代碼來製作小部件?Yii2:如何手動加載jQuery UI?
在我的情況下,我只需要sortable()
函數可用於我已有的一些現有代碼。我只想把它放在特定的頁面上,而不是所有的頁面上。所以我不能將它添加到AppAsset.php
。
我已經安裝https://github.com/yiisoft/yii2-jui但我該如何手動加載Javascript庫而不使用服務器端代碼來製作小部件?Yii2:如何手動加載jQuery UI?
在我的情況下,我只需要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 ...