yii2 在view文件中加载当前目录指定js文件内容,将其注册到本文件中而非引用js文件
$data = \backend\models\area\Area::find()->select(“code as id,area as text”)->asArray()->all();
$data = \yii\helpers\Json::htmlEncode($data);
$this->registerJs(“var data = {$data};”);
$this->registerJs($this->render(‘area.js’));