我正在使用modal bootstrap作为我的crud表单,我也使用yii2-ajaxcrud扩展,它扩展了gii生成器的单页crud。
一切都正常工作,保存模型,验证等......但是,我尝试使用javascript插件:(来自Leafo的粘性工具包)将我的操作按钮放在顶部。发生这种情况,当我访问我的'创建'在模态中查看发生以下错误:
QEventDispatcher: Failed to create QEventDispatcherWin32 internal window: 1407
Loading pages (1/6)
[> ] 0%
[======> ] 10%
QEventDispatcher: Failed to create QEventDispatcherWin32 internal window: 1407
从索引视图中,我访问了'创建'视图。当模态打开时,我在chrome检查器中看到了jquery和棒插件的注入。此外,使用ajax crud扩展我还可以访问直接URL生成的视图,因此棒插件可以工作。只访问模态中的视图才会出错。
可能是什么? 以下是我的主要相关代码。
"Uncaught TypeError: $ (...) stick_in_parent is not a function."
视图
//namespace app\modules\crm\controllers
public function actionCreate()
{
$request = Yii::$app->request;
$model = new Classes();
if($request->isAjax){
/*
* Process for ajax request
*/
Yii::$app->response->format = Response::FORMAT_JSON;
if($request->isGet){
return [
'title'=> "Create new Classes",
'content'=>$this->renderAjax('create', [
'model' => $model,
]),
'footer'=> Html::button('Close',['class'=>'btn btn-default pull-left','data-dismiss'=>"modal"]).
Html::button('Save',['class'=>'btn btn-primary','type'=>"submit"])
];
}else if($model->load($request->post()) && $model->save()){
return [
'forceReload'=>$this->htmlTableContainerId ,
'title'=> "Create new Classes",
'content'=>'<span class="text-success">Create Classes success</span>',
'footer'=> Html::button('Close',['class'=>'btn btn-default pull-left','data-dismiss'=>"modal"]).
Html::a('Create More',['create'],['class'=>'btn btn-primary','role'=>'modal-remote'])
];
}else{
return [
'title'=> "Create new Classes",
'content'=>$this->renderAjax('create', [
'model' => $model,
]),
'footer'=> Html::button('Close',['class'=>'btn btn-default pull-left','data-dismiss'=>"modal"]).
Html::button('Save',['class'=>'btn btn-primary','type'=>"submit"])
];
}
}else{
/*
* Process for non-ajax request
*/
if ($model->load($request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->ID]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
}
修改
当模态打开时,视图中的实际html generetade。我尝试删除重复包含的jquery(在模态和索引中),我得到它(使用Yii :: $ app-&gt; assetManager-&gt; bundles = [&#39; yii \ web \ JqueryAsset&#39; =&gt; ; false,],...)但错误仍然存在,所以我保留它。
// create view
<div class="panel-body" style="height: 600px">
<div class="classes-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>
</div>
$this->registerJsFile('http://leafo.net/sticky-kit/src/sticky-kit.js', ['depends' => [\yii\web\JqueryAsset::className()]]);
$this->registerJs("$('.panel-heading').stick_in_parent();");
答案 0 :(得分:2)
您应该使用renderAjax而不是renderPartial,因为renderPartial不会加载jquery库。